SlideShare a Scribd company logo
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 ) ;
}

More Related Content

What's hot

A08
A08A08
A08
lksoo
 
Common Programming Errors
Common Programming ErrorsCommon Programming Errors
Common Programming Errors
Nicole Ynne Estabillo
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
Prof Ansari
 
Introduction to c programming language
Introduction to c programming languageIntroduction to c programming language
Introduction to c programming language
sanjay 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 report
Raushan Pandey
 
Differences between c and c++
Differences between c and c++Differences between c and c++
Differences between c and c++
starlit electronics
 
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
jatin batra
 
# And ## operators in c
# And ## operators in c# And ## operators in c
# And ## operators in c
Dr. Prashant Vats
 
basics of c++
basics of c++basics of c++
basics of c++
gourav kottawar
 
Principles of object oriented programing
Principles of object oriented programingPrinciples of object oriented programing
Principles of object oriented programing
Ahammed 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
 
175035 cse lab 01
175035 cse lab 01175035 cse lab 01
175035 cse lab 01
Mahbubay Rabbani Mim
 
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
Vincenzo 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 branch
SAKSHIGAWADE2
 
Introduction to c language by nitesh
Introduction to c language by niteshIntroduction to c language by nitesh
Introduction to c language by nitesh
niteshcongreja321
 
C programming language
C programming languageC programming language
C programming language
Abin Rimal
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment

What's hot (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
 

Viewers also liked

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 01
hassaanciit
 
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 - 2010
leo lapworth
 
Sharia
ShariaSharia
Sharia
imalik8088
 
Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)hassaanciit
 
What is Sharia Law?
What is Sharia Law?What is Sharia Law?
What is Sharia Law?
John Guandolo
 
PowerPoint for Introduction to Office 2010
PowerPoint for Introduction to Office 2010PowerPoint for Introduction to Office 2010
PowerPoint for Introduction to Office 2010
mindysholder
 
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
Bob Patton, M.D., D.D.
 
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
 
Mazhab mazhab aqidah sem2
Mazhab mazhab aqidah sem2Mazhab mazhab aqidah sem2
Mazhab mazhab aqidah sem2
amira nurfahmida
 
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
Muhammad Tariq
 

Viewers also liked (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
 

Similar to Introduction to Computer and Programing - Lab2

Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
farishah
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
Mugilvannan11
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...
bhargavi804095
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
NEHARAJPUT239591
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
meharikiros2
 
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
CoolGamer16
 
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
bhargavi804095
 
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
PushkarNiroula1
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
Danielle780357
 
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
MayurWagh46
 
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
SanketShah544615
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdf
vino108206
 
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
sruthi yandapalli
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
Anandhasilambarasan D
 
CHAPTER 3
CHAPTER 3CHAPTER 3
CHAPTER 3
mohd_mizan
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptx
Vishwas459764
 
C introduction
C introductionC introduction
C introduction
Kamran
 
C programming languag for cse students
C programming languag for cse studentsC programming languag for cse students
C programming languag for cse students
Abdur Rahim
 

Similar to 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
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...
 
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
 
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
 
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
 

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 ) ; }