SlideShare uma empresa Scribd logo
1 de 2
Baixar para ler offline
Lab 2 - Getting Started with C
1. Objectives
The objective of this lab is to make student understand their first C programs, its environment
how to compile it and Operator precedence.
2. Outcome
I. At the end of this lab student will know how to write a C program.
II. Student will understand the process of compiling and getting output.
III. Student will understand various C Operators.
3. Introduction
3.1 First C Program
C is a high-level programming language and that you need a C compiler to translate your C
programs into binary code that your computer can understand and execute. In this lab you'll
learn to write your first C program and the basics of a C program, such as
 The #include directive
 Header files
 Comments
 The main() function
 The return statement
 The exit() function
 The newline character (n)
 The void data type
 Translating a C program into an executable file
 Debugging
Example:
 This is a very simple C program, which is saved in a file called Test.c. Note that the
name of a C program file must have an extension of .c.
 In C, #include forms a preprocessor directive that tells the C preprocessor to look for a
file and place the contents of the file in the location where the #include directive
indicates.
/* Test.c: This is my first C program */
#include <stdio.h>
void main()
{
printf ("Howdy! This is my first C
program.");
}
 The ``main'' function establishes the overall logic of the code. All C codes must have a
``main'' function.
 Our Test.c code calls printf, an output function from the I/O (input/output) library
(defined in the file stdio.h). The printf line prints the message Howdy! This is my first
C program ' on ``stdout'' (the output stream )
 ``new line'' character, which brings the cursor onto the next line.
 All functions in C can return values. The main () function itself returns a value. By
default, main () returns an integer. Return 0; that indicates that 0 is returned from the
main () function and the program is terminated normally.
3.2 Compilation and Linking:
 First, a program written in C, called source code, is made. Then the source code is
compiled by a C compiler, which creates a new file. The new file is an object file.
 You cannot execute the object file because there is some function code missing. You
have to finish the next step: linking. Linking is done by invoking a special program
called a linker, which normally comes with the compiler package.
 A linker is used to link together the object file, the ANSI standard C library, and other
user-generated libraries to produce an executable file—the binary code. In this stage,
the binary code of the library functions that are called in the source code is combined
with the object file; the result is saved into a new file—an executable file.
Example:
#include <stdio.h>
void main( )
{
int p, n ;
float r, si ;
p = 1000 ;
n = 3 ;
r = 8.5 ;
/* formula for simple interest*/
si = p * n * r / 100 ;
printf ( "%f" , si ) ;
}

Mais conteúdo relacionado

Mais procurados

The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming LanguageProf Ansari
 
Introduction to c programming language
Introduction to c programming languageIntroduction to c programming language
Introduction to c programming languagesanjay joshi
 
My first program in c, hello world !
My first program in c, hello world !My first program in c, hello world !
My first program in c, hello world !Rumman Ansari
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training reportRaushan Pandey
 
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREC and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREjatin batra
 
Principles of object oriented programing
Principles of object oriented programingPrinciples of object oriented programing
Principles of object oriented programingAhammed Alamin
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Rohit Singh
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageVincenzo De Florio
 
Computer experiments 1^j2^j3^j4^j8^j9. d24 ^j sakshi gawade cs branch
Computer experiments   1^j2^j3^j4^j8^j9. d24 ^j sakshi gawade cs branchComputer experiments   1^j2^j3^j4^j8^j9. d24 ^j sakshi gawade cs branch
Computer experiments 1^j2^j3^j4^j8^j9. d24 ^j sakshi gawade cs branchSAKSHIGAWADE2
 
Introduction to c language by nitesh
Introduction to c language by niteshIntroduction to c language by nitesh
Introduction to c language by niteshniteshcongreja321
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 

Mais procurados (20)

A08
A08A08
A08
 
Common Programming Errors
Common Programming ErrorsCommon Programming Errors
Common Programming Errors
 
C vs c++
C vs c++C vs c++
C vs c++
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
 
Introduction to c programming language
Introduction to c programming languageIntroduction to c programming language
Introduction to c programming language
 
My first program in c, hello world !
My first program in c, hello world !My first program in c, hello world !
My first program in c, hello world !
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training report
 
Differences between c and c++
Differences between c and c++Differences between c and c++
Differences between c and c++
 
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREC and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
 
# And ## operators in c
# And ## operators in c# And ## operators in c
# And ## operators in c
 
basics of c++
basics of c++basics of c++
basics of c++
 
Principles of object oriented programing
Principles of object oriented programingPrinciples of object oriented programing
Principles of object oriented programing
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)
 
175035 cse lab 01
175035 cse lab 01175035 cse lab 01
175035 cse lab 01
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming Language
 
Computer experiments 1^j2^j3^j4^j8^j9. d24 ^j sakshi gawade cs branch
Computer experiments   1^j2^j3^j4^j8^j9. d24 ^j sakshi gawade cs branchComputer experiments   1^j2^j3^j4^j8^j9. d24 ^j sakshi gawade cs branch
Computer experiments 1^j2^j3^j4^j8^j9. d24 ^j sakshi gawade cs branch
 
C vs c++
C vs c++C vs c++
C vs c++
 
Introduction to c language by nitesh
Introduction to c language by niteshIntroduction to c language by nitesh
Introduction to c language by nitesh
 
C programming language
C programming languageC programming language
C programming language
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 

Destaque

Introduction to Computer and Programming - Lecture 02
Introduction to Computer and Programming - Lecture 02Introduction to Computer and Programming - Lecture 02
Introduction to Computer and Programming - Lecture 02hassaanciit
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04hassaanciit
 
Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01hassaanciit
 
Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03hassaanciit
 
DBIx::Class introduction - 2010
DBIx::Class introduction - 2010DBIx::Class introduction - 2010
DBIx::Class introduction - 2010leo lapworth
 
Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)hassaanciit
 
PowerPoint for Introduction to Office 2010
PowerPoint for Introduction to Office 2010PowerPoint for Introduction to Office 2010
PowerPoint for Introduction to Office 2010mindysholder
 
Islamic Studies - Course Outline
Islamic Studies - Course OutlineIslamic Studies - Course Outline
Islamic Studies - Course Outlinehassaanciit
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming ConceptsJussi Pohjolainen
 
Circuits Lecture 5 with examples
Circuits Lecture 5 with examplesCircuits Lecture 5 with examples
Circuits Lecture 5 with exampleshassaanciit
 
[Slideshare] tafaqqahu-(2015)-#6 e-responding-islamaphobia-regardg-islamic-la...
[Slideshare] tafaqqahu-(2015)-#6 e-responding-islamaphobia-regardg-islamic-la...[Slideshare] tafaqqahu-(2015)-#6 e-responding-islamaphobia-regardg-islamic-la...
[Slideshare] tafaqqahu-(2015)-#6 e-responding-islamaphobia-regardg-islamic-la...Zhulkeflee Ismail
 
Ya rasool allah kehna ummat ka mutaffiqa moaqif by mufti muhammad khan qadri
Ya rasool allah kehna ummat ka mutaffiqa moaqif by mufti muhammad khan qadriYa rasool allah kehna ummat ka mutaffiqa moaqif by mufti muhammad khan qadri
Ya rasool allah kehna ummat ka mutaffiqa moaqif by mufti muhammad khan qadriMuhammad Tariq
 

Destaque (20)

Introduction to Computer and Programming - Lecture 02
Introduction to Computer and Programming - Lecture 02Introduction to Computer and Programming - Lecture 02
Introduction to Computer and Programming - Lecture 02
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01
 
Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03
 
DBIx::Class introduction - 2010
DBIx::Class introduction - 2010DBIx::Class introduction - 2010
DBIx::Class introduction - 2010
 
Sharia
ShariaSharia
Sharia
 
Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)
 
What is Sharia Law?
What is Sharia Law?What is Sharia Law?
What is Sharia Law?
 
PowerPoint for Introduction to Office 2010
PowerPoint for Introduction to Office 2010PowerPoint for Introduction to Office 2010
PowerPoint for Introduction to Office 2010
 
Islam s6 shari'a law and dhimmi
Islam s6 shari'a law and dhimmiIslam s6 shari'a law and dhimmi
Islam s6 shari'a law and dhimmi
 
Islamic Studies - Course Outline
Islamic Studies - Course OutlineIslamic Studies - Course Outline
Islamic Studies - Course Outline
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
 
Circuits Lecture 5 with examples
Circuits Lecture 5 with examplesCircuits Lecture 5 with examples
Circuits Lecture 5 with examples
 
ECA - Lecture 03
ECA - Lecture 03ECA - Lecture 03
ECA - Lecture 03
 
ICP - Lecture 9
ICP - Lecture 9ICP - Lecture 9
ICP - Lecture 9
 
Fiqh usool e-deen
Fiqh usool e-deenFiqh usool e-deen
Fiqh usool e-deen
 
[Slideshare] tafaqqahu-(2015)-#6 e-responding-islamaphobia-regardg-islamic-la...
[Slideshare] tafaqqahu-(2015)-#6 e-responding-islamaphobia-regardg-islamic-la...[Slideshare] tafaqqahu-(2015)-#6 e-responding-islamaphobia-regardg-islamic-la...
[Slideshare] tafaqqahu-(2015)-#6 e-responding-islamaphobia-regardg-islamic-la...
 
Step natural
Step naturalStep natural
Step natural
 
Mazhab mazhab aqidah sem2
Mazhab mazhab aqidah sem2Mazhab mazhab aqidah sem2
Mazhab mazhab aqidah sem2
 
Ya rasool allah kehna ummat ka mutaffiqa moaqif by mufti muhammad khan qadri
Ya rasool allah kehna ummat ka mutaffiqa moaqif by mufti muhammad khan qadriYa rasool allah kehna ummat ka mutaffiqa moaqif by mufti muhammad khan qadri
Ya rasool allah kehna ummat ka mutaffiqa moaqif by mufti muhammad khan qadri
 

Semelhante a Introduction to Computer and Programing - Lab2

Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c languagefarishah
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptxMugilvannan11
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxNEHARAJPUT239591
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJmeharikiros2
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxCoolGamer16
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itPushkarNiroula1
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docMayurWagh46
 
Unit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxUnit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxSanketShah544615
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdfvino108206
 
Compiling and linking of a c code
Compiling and linking of a c codeCompiling and linking of a c code
Compiling and linking of a c codesruthi yandapalli
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptxVishwas459764
 
C introduction
C introductionC introduction
C introductionKamran
 
C programming languag for cse students
C programming languag for cse studentsC programming languag for cse students
C programming languag for cse studentsAbdur Rahim
 

Semelhante a Introduction to Computer and Programing - Lab2 (20)

Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to it
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).doc
 
Unit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxUnit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptx
 
OVERVIEW OF ‘C’ PROGRAM
OVERVIEW OF ‘C’ PROGRAMOVERVIEW OF ‘C’ PROGRAM
OVERVIEW OF ‘C’ PROGRAM
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdf
 
Compiling and linking of a c code
Compiling and linking of a c codeCompiling and linking of a c code
Compiling and linking of a c code
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
2621008 - C++ 1
2621008 -  C++ 12621008 -  C++ 1
2621008 - C++ 1
 
CHAPTER 3
CHAPTER 3CHAPTER 3
CHAPTER 3
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptx
 
C introduction
C introductionC introduction
C introduction
 
C programming languag for cse students
C programming languag for cse studentsC programming languag for cse students
C programming languag for cse students
 
Cp week _2.
Cp week _2.Cp week _2.
Cp week _2.
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 

Introduction to Computer and Programing - Lab2

  • 1. Lab 2 - Getting Started with C 1. Objectives The objective of this lab is to make student understand their first C programs, its environment how to compile it and Operator precedence. 2. Outcome I. At the end of this lab student will know how to write a C program. II. Student will understand the process of compiling and getting output. III. Student will understand various C Operators. 3. Introduction 3.1 First C Program C is a high-level programming language and that you need a C compiler to translate your C programs into binary code that your computer can understand and execute. In this lab you'll learn to write your first C program and the basics of a C program, such as  The #include directive  Header files  Comments  The main() function  The return statement  The exit() function  The newline character (n)  The void data type  Translating a C program into an executable file  Debugging Example:  This is a very simple C program, which is saved in a file called Test.c. Note that the name of a C program file must have an extension of .c.  In C, #include forms a preprocessor directive that tells the C preprocessor to look for a file and place the contents of the file in the location where the #include directive indicates. /* Test.c: This is my first C program */ #include <stdio.h> void main() { printf ("Howdy! This is my first C program."); }
  • 2.  The ``main'' function establishes the overall logic of the code. All C codes must have a ``main'' function.  Our Test.c code calls printf, an output function from the I/O (input/output) library (defined in the file stdio.h). The printf line prints the message Howdy! This is my first C program ' on ``stdout'' (the output stream )  ``new line'' character, which brings the cursor onto the next line.  All functions in C can return values. The main () function itself returns a value. By default, main () returns an integer. Return 0; that indicates that 0 is returned from the main () function and the program is terminated normally. 3.2 Compilation and Linking:  First, a program written in C, called source code, is made. Then the source code is compiled by a C compiler, which creates a new file. The new file is an object file.  You cannot execute the object file because there is some function code missing. You have to finish the next step: linking. Linking is done by invoking a special program called a linker, which normally comes with the compiler package.  A linker is used to link together the object file, the ANSI standard C library, and other user-generated libraries to produce an executable file—the binary code. In this stage, the binary code of the library functions that are called in the source code is combined with the object file; the result is saved into a new file—an executable file. Example: #include <stdio.h> void main( ) { int p, n ; float r, si ; p = 1000 ; n = 3 ; r = 8.5 ; /* formula for simple interest*/ si = p * n * r / 100 ; printf ( "%f" , si ) ; }