Thanks to visit codestin.com
Credit goes to www.slideshare.net

How C
Program
Execute
To type your C program you need a program called Editor
Example:
Notepad
Notepad++
or any IDE
Once the program has been typed it needs to be converted to machine language (0s
and 1s) before the machine can execute it .
To carry out this conversion we need another program called Compiler. Compiler
vendors provide an Integrated Development Environment (IDE) which consists of an
Editor as well as the Compiler.
Compiler Example:
gcc
IDE Example:
Turbo C,
Visual C++ ,
Borland C++
Write down program in IDE
and save it with extension(.c)
example: program_name.c
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Compile The Program
Compile Completed
no error is detected
and object file also created
Example: program_name.obj
Execution
with
Explanation
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Main Memory
Memory Address
102543
142586
135545
135487
It is a preprocessor command
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Main Memory
Memory Address
102543
142586
135545
135487
It is the main function where the program execution begins
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Main Memory
Memory Address
102543
142586
135545
135487
First open brace of main function
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Main Memory
Memory Address
102543
142586
135545
135487
Memory allocation for three variable a,b,c
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Memory
int a
int c
Main Memory
int b
Address
102543
142586
135545
135487
printf(...) is a function which is use to show any message to
the user
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Memory
int a
int c
Main Memory
int b
Address
102543
142586
135545
135487
User’s console or cmd
message to the user
Enter two numbers to add
scanf(...) is another function available in C which is use to take
value form user by keyboard
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Memory
int a
int c
Main Memory
int b
Address
102543
142586
135545
135487
User’s console or cmd
give the value of a=6 and b=5
Enter two numbers to add
6
5
Insertion of a and b in memory
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Memory
int a
int c
Main Memory
int b
Address
102543
142586
135545
135487
Insertion of a and b in memory
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Memory
6
int c
Main Memory
5
Address
102543
142586
135545
135487
Arithmatic addition operation
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Memory
6
int c
Main Memory
5
Address
102543
142586
135545
135487
Arithmetic Addition Operation
6 5 =+ 11
Arithmetic addition operation
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Memory
6
11
Main Memory
5
Address
102543
142586
135545
135487
printf(...) is a function which is use to show any message to
the user.It shows the value of c variable to the user.
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Memory
Main Memory
Address
102543
142586
135545
135487
6
11
5
User’s console or cmd
give the value of c = 11 (answer)
Enter two numbers to add
6
5
Sum of entered numbers = 11
Press any key to continue . . .
It says that it is terminates the main() function and returns the
value 0.
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Memory
Main Memory
Address
102543
142586
135545
135487
6
11
5
last close brace of main function
1. #include<stdio.h>
2. int main()
3. {
4. int a, b, c;
5.
6. printf("Enter two numbers to addn");
7. scanf("%d%d",&a,&b);
8.
9. c = a + b;
10.
11. printf("Sum of entered numbers = %dn",c);
12.
13. return 0;
14. }
Memory
Main Memory
Address
102543
142586
135545
135487
6
11
5
Thank
You

How c program execute in c program

  • 1.
  • 2.
    To type yourC program you need a program called Editor Example: Notepad Notepad++ or any IDE
  • 3.
    Once the programhas been typed it needs to be converted to machine language (0s and 1s) before the machine can execute it .
  • 4.
    To carry outthis conversion we need another program called Compiler. Compiler vendors provide an Integrated Development Environment (IDE) which consists of an Editor as well as the Compiler. Compiler Example: gcc IDE Example: Turbo C, Visual C++ , Borland C++
  • 5.
    Write down programin IDE and save it with extension(.c) example: program_name.c
  • 6.
    1. #include<stdio.h> 2. intmain() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. }
  • 7.
  • 8.
    Compile Completed no erroris detected and object file also created Example: program_name.obj
  • 9.
  • 10.
    1. #include<stdio.h> 2. intmain() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Main Memory Memory Address 102543 142586 135545 135487
  • 11.
    It is apreprocessor command 1. #include<stdio.h> 2. int main() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Main Memory Memory Address 102543 142586 135545 135487
  • 12.
    It is themain function where the program execution begins 1. #include<stdio.h> 2. int main() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Main Memory Memory Address 102543 142586 135545 135487
  • 13.
    First open braceof main function 1. #include<stdio.h> 2. int main() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Main Memory Memory Address 102543 142586 135545 135487
  • 14.
    Memory allocation forthree variable a,b,c 1. #include<stdio.h> 2. int main() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Memory int a int c Main Memory int b Address 102543 142586 135545 135487
  • 15.
    printf(...) is afunction which is use to show any message to the user 1. #include<stdio.h> 2. int main() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Memory int a int c Main Memory int b Address 102543 142586 135545 135487
  • 16.
    User’s console orcmd message to the user Enter two numbers to add
  • 17.
    scanf(...) is anotherfunction available in C which is use to take value form user by keyboard 1. #include<stdio.h> 2. int main() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Memory int a int c Main Memory int b Address 102543 142586 135545 135487
  • 18.
    User’s console orcmd give the value of a=6 and b=5 Enter two numbers to add 6 5
  • 19.
    Insertion of aand b in memory 1. #include<stdio.h> 2. int main() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Memory int a int c Main Memory int b Address 102543 142586 135545 135487
  • 20.
    Insertion of aand b in memory 1. #include<stdio.h> 2. int main() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Memory 6 int c Main Memory 5 Address 102543 142586 135545 135487
  • 21.
    Arithmatic addition operation 1.#include<stdio.h> 2. int main() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Memory 6 int c Main Memory 5 Address 102543 142586 135545 135487
  • 22.
  • 23.
    Arithmetic addition operation 1.#include<stdio.h> 2. int main() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Memory 6 11 Main Memory 5 Address 102543 142586 135545 135487
  • 24.
    printf(...) is afunction which is use to show any message to the user.It shows the value of c variable to the user. 1. #include<stdio.h> 2. int main() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Memory Main Memory Address 102543 142586 135545 135487 6 11 5
  • 25.
    User’s console orcmd give the value of c = 11 (answer) Enter two numbers to add 6 5 Sum of entered numbers = 11 Press any key to continue . . .
  • 26.
    It says thatit is terminates the main() function and returns the value 0. 1. #include<stdio.h> 2. int main() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Memory Main Memory Address 102543 142586 135545 135487 6 11 5
  • 27.
    last close braceof main function 1. #include<stdio.h> 2. int main() 3. { 4. int a, b, c; 5. 6. printf("Enter two numbers to addn"); 7. scanf("%d%d",&a,&b); 8. 9. c = a + b; 10. 11. printf("Sum of entered numbers = %dn",c); 12. 13. return 0; 14. } Memory Main Memory Address 102543 142586 135545 135487 6 11 5
  • 28.