Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

Computer Programming

CS 101

Dr. Daya Sagar Gupta

Department of CSE, RGIPT Jais

DS Gupta (RGIPT Jais) Computer Programming 1/8


Lecture No. - 4

DS Gupta (RGIPT Jais) Computer Programming 2/8


Computer Programming

A simple C program

#i n c l u d e <s t d i o . h>
v o i d main ( )
{
p r i n t f ( ” H e l l o World ! ” ) ;
}

Use Linux OS if you are comfortable with it


Type in an editor (gedit, vi, vim, turbo C, etc)
Extension is .c (like hello.c)
Compile it and run with any compiler
For linux envirnoment, use terminal to compile it with ”gcc filename.c” com-
mand
An output file is created in same folder with name a.out.
Run it with ”./a.out” command

DS Gupta (RGIPT Jais) Computer Programming 3/8


Computer Programming

A simple C program

#i n c l u d e <s t d i o . h>
v o i d main ( )
{
p r i n t f ( ” H e l l o World ! ” ) ;
}

Use Linux OS if you are comfortable with it


Type in an editor (gedit, vi, vim, turbo C, etc)
Extension is .c (like hello.c)
Compile it and run with any compiler
For linux envirnoment, use terminal to compile it with ”gcc filename.c” com-
mand
An output file is created in same folder with name a.out.
Run it with ”./a.out” command

DS Gupta (RGIPT Jais) Computer Programming 3/8


Computer Programming

A simple C program

#i n c l u d e <s t d i o . h>
v o i d main ( )
{
p r i n t f ( ” H e l l o World ! ” ) ;
}

Use Linux OS if you are comfortable with it


Type in an editor (gedit, vi, vim, turbo C, etc)
Extension is .c (like hello.c)
Compile it and run with any compiler
For linux envirnoment, use terminal to compile it with ”gcc filename.c” com-
mand
An output file is created in same folder with name a.out.
Run it with ”./a.out” command

DS Gupta (RGIPT Jais) Computer Programming 3/8


Computer Programming

A simple C program

#i n c l u d e <s t d i o . h>
v o i d main ( )
{
p r i n t f ( ” H e l l o World ! ” ) ;
}

Use Linux OS if you are comfortable with it


Type in an editor (gedit, vi, vim, turbo C, etc)
Extension is .c (like hello.c)
Compile it and run with any compiler
For linux envirnoment, use terminal to compile it with ”gcc filename.c” com-
mand
An output file is created in same folder with name a.out.
Run it with ”./a.out” command

DS Gupta (RGIPT Jais) Computer Programming 3/8


Computer Programming

A simple C program

#i n c l u d e <s t d i o . h>
v o i d main ( )
{
p r i n t f ( ” H e l l o World ! ” ) ;
}

Use Linux OS if you are comfortable with it


Type in an editor (gedit, vi, vim, turbo C, etc)
Extension is .c (like hello.c)
Compile it and run with any compiler
For linux envirnoment, use terminal to compile it with ”gcc filename.c” com-
mand
An output file is created in same folder with name a.out.
Run it with ”./a.out” command

DS Gupta (RGIPT Jais) Computer Programming 3/8


Computer Programming

A simple C program

#i n c l u d e <s t d i o . h>
v o i d main ( )
{
p r i n t f ( ” H e l l o World ! ” ) ;
}

Use Linux OS if you are comfortable with it


Type in an editor (gedit, vi, vim, turbo C, etc)
Extension is .c (like hello.c)
Compile it and run with any compiler
For linux envirnoment, use terminal to compile it with ”gcc filename.c” com-
mand
An output file is created in same folder with name a.out.
Run it with ”./a.out” command

DS Gupta (RGIPT Jais) Computer Programming 3/8


Computer Programming

Program explanation

C programs mainly contain two things: functions and variables.


Functions are simply commands which will says what work is to be done.
Variables are used to store the values which will be useful in executing those
functions.
stdio.h: standard input output header file.
#include or #define is called preprocessor directives.
Preprocessors include the content of header files in the program to execute
corresponding functions.
main(){ } is a function. C progaram must have a main function to execute it.
Every function must have a parenthesis () after it. Functions other than main
can have any name.

DS Gupta (RGIPT Jais) Computer Programming 4/8


Computer Programming

Program explanation

C programs mainly contain two things: functions and variables.


Functions are simply commands which will says what work is to be done.
Variables are used to store the values which will be useful in executing those
functions.
stdio.h: standard input output header file.
#include or #define is called preprocessor directives.
Preprocessors include the content of header files in the program to execute
corresponding functions.
main(){ } is a function. C progaram must have a main function to execute it.
Every function must have a parenthesis () after it. Functions other than main
can have any name.

DS Gupta (RGIPT Jais) Computer Programming 4/8


Computer Programming

Program explanation

C programs mainly contain two things: functions and variables.


Functions are simply commands which will says what work is to be done.
Variables are used to store the values which will be useful in executing those
functions.
stdio.h: standard input output header file.
#include or #define is called preprocessor directives.
Preprocessors include the content of header files in the program to execute
corresponding functions.
main(){ } is a function. C progaram must have a main function to execute it.
Every function must have a parenthesis () after it. Functions other than main
can have any name.

DS Gupta (RGIPT Jais) Computer Programming 4/8


Computer Programming

Program explanation

C programs mainly contain two things: functions and variables.


Functions are simply commands which will says what work is to be done.
Variables are used to store the values which will be useful in executing those
functions.
stdio.h: standard input output header file.
#include or #define is called preprocessor directives.
Preprocessors include the content of header files in the program to execute
corresponding functions.
main(){ } is a function. C progaram must have a main function to execute it.
Every function must have a parenthesis () after it. Functions other than main
can have any name.

DS Gupta (RGIPT Jais) Computer Programming 4/8


Computer Programming

Program explanation

C programs mainly contain two things: functions and variables.


Functions are simply commands which will says what work is to be done.
Variables are used to store the values which will be useful in executing those
functions.
stdio.h: standard input output header file.
#include or #define is called preprocessor directives.
Preprocessors include the content of header files in the program to execute
corresponding functions.
main(){ } is a function. C progaram must have a main function to execute it.
Every function must have a parenthesis () after it. Functions other than main
can have any name.

DS Gupta (RGIPT Jais) Computer Programming 4/8


Computer Programming

Program explanation

C programs mainly contain two things: functions and variables.


Functions are simply commands which will says what work is to be done.
Variables are used to store the values which will be useful in executing those
functions.
stdio.h: standard input output header file.
#include or #define is called preprocessor directives.
Preprocessors include the content of header files in the program to execute
corresponding functions.
main(){ } is a function. C progaram must have a main function to execute it.
Every function must have a parenthesis () after it. Functions other than main
can have any name.

DS Gupta (RGIPT Jais) Computer Programming 4/8


Computer Programming

Program explanation

C programs mainly contain two things: functions and variables.


Functions are simply commands which will says what work is to be done.
Variables are used to store the values which will be useful in executing those
functions.
stdio.h: standard input output header file.
#include or #define is called preprocessor directives.
Preprocessors include the content of header files in the program to execute
corresponding functions.
main(){ } is a function. C progaram must have a main function to execute it.
Every function must have a parenthesis () after it. Functions other than main
can have any name.

DS Gupta (RGIPT Jais) Computer Programming 4/8


Computer Programming

Program explanation

C programs mainly contain two things: functions and variables.


Functions are simply commands which will says what work is to be done.
Variables are used to store the values which will be useful in executing those
functions.
stdio.h: standard input output header file.
#include or #define is called preprocessor directives.
Preprocessors include the content of header files in the program to execute
corresponding functions.
main(){ } is a function. C progaram must have a main function to execute it.
Every function must have a parenthesis () after it. Functions other than main
can have any name.

DS Gupta (RGIPT Jais) Computer Programming 4/8


Computer Programming

Program explanation

C programs mainly contain two things: functions and variables.


Functions are simply commands which will says what work is to be done.
Variables are used to store the values which will be useful in executing those
functions.
stdio.h: standard input output header file.
#include or #define is called preprocessor directives.
Preprocessors include the content of header files in the program to execute
corresponding functions.
main(){ } is a function. C progaram must have a main function to execute it.
Every function must have a parenthesis () after it. Functions other than main
can have any name.

DS Gupta (RGIPT Jais) Computer Programming 4/8


Computer Programming

Program explanation

{ } after the function name indicates the body of the function.


printf is also a function which can be included in the library (stdio.h).
Every function has an argument list within the parenthesis.
e.g., the function printf have ”Hello World!” as a single argument.
Every function in C returns a value. If nothing has been returned, void is used.

DS Gupta (RGIPT Jais) Computer Programming 5/8


Computer Programming

Program explanation

{ } after the function name indicates the body of the function.


printf is also a function which can be included in the library (stdio.h).
Every function has an argument list within the parenthesis.
e.g., the function printf have ”Hello World!” as a single argument.
Every function in C returns a value. If nothing has been returned, void is used.

DS Gupta (RGIPT Jais) Computer Programming 5/8


Computer Programming

Program explanation

{ } after the function name indicates the body of the function.


printf is also a function which can be included in the library (stdio.h).
Every function has an argument list within the parenthesis.
e.g., the function printf have ”Hello World!” as a single argument.
Every function in C returns a value. If nothing has been returned, void is used.

DS Gupta (RGIPT Jais) Computer Programming 5/8


Computer Programming

Program explanation

{ } after the function name indicates the body of the function.


printf is also a function which can be included in the library (stdio.h).
Every function has an argument list within the parenthesis.
e.g., the function printf have ”Hello World!” as a single argument.
Every function in C returns a value. If nothing has been returned, void is used.

DS Gupta (RGIPT Jais) Computer Programming 5/8


Computer Programming

Program explanation

{ } after the function name indicates the body of the function.


printf is also a function which can be included in the library (stdio.h).
Every function has an argument list within the parenthesis.
e.g., the function printf have ”Hello World!” as a single argument.
Every function in C returns a value. If nothing has been returned, void is used.

DS Gupta (RGIPT Jais) Computer Programming 5/8


Computer Programming

Compilation Process

C uses GNU Compiler Collection (GCC) to compile the program.


Why compiler?
Generally, the programs are written in high-level language (HLL) like english.
Computers only understand machine-level language (MLL) i.e., in the forms of
0’s and 1’s.
To translate HLL into MLL, compiler along with some other tools is used.

DS Gupta (RGIPT Jais) Computer Programming 6/8


Computer Programming

Compilation Process

C uses GNU Compiler Collection (GCC) to compile the program.


Why compiler?
Generally, the programs are written in high-level language (HLL) like english.
Computers only understand machine-level language (MLL) i.e., in the forms of
0’s and 1’s.
To translate HLL into MLL, compiler along with some other tools is used.

DS Gupta (RGIPT Jais) Computer Programming 6/8


Computer Programming

Compilation Process

C uses GNU Compiler Collection (GCC) to compile the program.


Why compiler?
Generally, the programs are written in high-level language (HLL) like english.
Computers only understand machine-level language (MLL) i.e., in the forms of
0’s and 1’s.
To translate HLL into MLL, compiler along with some other tools is used.

DS Gupta (RGIPT Jais) Computer Programming 6/8


Computer Programming

Compilation Process

C uses GNU Compiler Collection (GCC) to compile the program.


Why compiler?
Generally, the programs are written in high-level language (HLL) like english.
Computers only understand machine-level language (MLL) i.e., in the forms of
0’s and 1’s.
To translate HLL into MLL, compiler along with some other tools is used.

DS Gupta (RGIPT Jais) Computer Programming 6/8


Computer Programming

Compilation Process

C uses GNU Compiler Collection (GCC) to compile the program.


Why compiler?
Generally, the programs are written in high-level language (HLL) like english.
Computers only understand machine-level language (MLL) i.e., in the forms of
0’s and 1’s.
To translate HLL into MLL, compiler along with some other tools is used.

DS Gupta (RGIPT Jais) Computer Programming 6/8


Computer Programming

Compilation Process
HLL file.c

Preprocessor $gcc -E file.c>file.i

Pure HLL file.i

Compiler $gcc -S
file.c or file.i
Assembly Language file.s

Assembler $gcc -c file.c


or file.s
M/c code (relocatable) file.o

Loader/linker $gcc -o test file.o

Target M/c code test.out


DS Gupta (RGIPT Jais) Computer Programming 7/8
Computer Programming

Compilation Process
HLL file.c

Preprocessor $gcc -E file.c>file.i

Pure HLL file.i

Compiler $gcc -S
file.c or file.i
Assembly Language file.s

Assembler $gcc -c file.c


or file.s
M/c code (relocatable) file.o

Loader/linker $gcc -o test file.o

Target M/c code test.out


DS Gupta (RGIPT Jais) Computer Programming 7/8
Computer Programming

Compilation Process

Preprocessor:
Removal of comments
File incusion (#include<>)
Micro expansion (#define<>)
Compiler: Translates HLL into Assembly language (Low-level language).
Assembler: Translates assembly language into M/c code (relocatable).

DS Gupta (RGIPT Jais) Computer Programming 8/8


Computer Programming

Compilation Process

Preprocessor:
Removal of comments
File incusion (#include<>)
Micro expansion (#define<>)
Compiler: Translates HLL into Assembly language (Low-level language).
Assembler: Translates assembly language into M/c code (relocatable).

DS Gupta (RGIPT Jais) Computer Programming 8/8


Computer Programming

Compilation Process

Preprocessor:
Removal of comments
File incusion (#include<>)
Micro expansion (#define<>)
Compiler: Translates HLL into Assembly language (Low-level language).
Assembler: Translates assembly language into M/c code (relocatable).

DS Gupta (RGIPT Jais) Computer Programming 8/8


Computer Programming

Compilation Process

Preprocessor:
Removal of comments
File incusion (#include<>)
Micro expansion (#define<>)
Compiler: Translates HLL into Assembly language (Low-level language).
Assembler: Translates assembly language into M/c code (relocatable).

DS Gupta (RGIPT Jais) Computer Programming 8/8


Computer Programming

Compilation Process

Preprocessor:
Removal of comments
File incusion (#include<>)
Micro expansion (#define<>)
Compiler: Translates HLL into Assembly language (Low-level language).
Assembler: Translates assembly language into M/c code (relocatable).

DS Gupta (RGIPT Jais) Computer Programming 8/8


Computer Programming

Compilation Process

Preprocessor:
Removal of comments
File incusion (#include<>)
Micro expansion (#define<>)
Compiler: Translates HLL into Assembly language (Low-level language).
Assembler: Translates assembly language into M/c code (relocatable).

DS Gupta (RGIPT Jais) Computer Programming 8/8


Computer Programming

Compilation Process

Preprocessor:
Removal of comments
File incusion (#include<>)
Micro expansion (#define<>)
Compiler: Translates HLL into Assembly language (Low-level language).
Assembler: Translates assembly language into M/c code (relocatable).

DS Gupta (RGIPT Jais) Computer Programming 8/8

You might also like