C Fundamentals Learners Handbook
C Fundamentals Learners Handbook
Roll No :
MODULE I
Strong Foundation.
Fundamentals of Programming and problem solving
Time
S.No Topic Time Day
Duration
2
S
Time
.
Topic Time Day
N Duration
o
20. Recap 1 hour 09.00 to 10.00
3
1.Hardware
computer chassis
CPU
Registers
cache
RAM
Hard disc
Motherboard
Volatile :
Non Volatile :
SMPS :
4
2.SOFTWARE
Application S/w
System S/w
o Application software
o System software
Select the software category of Ms word
o Application software
o System software
Select the software category of chrome
o Application software
o System software
Select the software category of Compiler
o Application software
o System software
Select the software category of windows 11
o Application software
o System software
5
3.Language of computers
BIT
BYTE
KB
MB
GB
TB
PB
6
3.Language of computers
3E 05
Opcode 06 03
00 80
MVI A, 05
assembly MVI B, 03
ADD B
c A=5+3
compiler
interpreter
7
Select that translates source code line by line
o compiler
o interpreter
The computer can understand at the lowest level
o 0 and 1s
o Decimal number system
o HEX
o Octal
The More human readable instruction is
o Assembly
o Machine Language
The hardware dependent language (Architecture of CPU) or low-level language are
(multiple answers are correct)
☐Assembly language
☐Machine language
☐High level language
☐Natural language
The Executable file in windows will have
o .exe extension
o .apk extension
o .jpg extension
o .jpeg extension
The programming language consist of only 0’s and 1’s is
o Assembly language
o Machine language
o High level language
o Natural language
8
When you run a program or exe stored in the Hard disc
o Computational logic
o Algorithmic Thinking
o Communication skills
The More human readable is
o Assembly
o Natural language
Select that translates source code and generates exe
o compiler
o interpreter
Select the application software
☐ operating system
☐ device driver
☐ Microsoft teams
☐ file explorer
Select the application software
☐ adobe reader
☐ calendar
☐ calculator
☐ android
When you uninstall a system software the other programs in the computer may not
work properly
☐ True
☐ False
9
10
4.C programming language history
(BCPL) B->C :
o Then you should know the words that have meaning (like in English dictionary
the words have special meaning is called as key words in programming
language)
o Then you should know the grammar rules to frame sentence (meaning full
sentence)
o After that you can write paragraph or essay or poem
11
0000000
00000001
00000010
00000011
00000100
00000101
00000110
00000111
00001000
00001001
00001010
00001011
00001100
00001101
00001110
00001111
00010000
00010001
00010010
11111100
11111101
11111110
11111111
A = 65 a=97
B = 66 b=98
Space=32
12
English Tamil C
13
DATA TYPES IN C
char a;
char b= 65;
char a= 10;
Ones compliment
14
char a=-1;
1 0 0 0 0 0 1 0
0 0 1 1 1 0 1 0
15
0 0 1 1 1 1 1 0
0 1 1 1 1 0 1 1
0 0 0 0 0 0 0 0
0 1 0 1 1 0 1 0
1 0 1 1 1 0 1 1
1 1 1 1 1 0 1 0
0 0 1 0 0 0 1 0
0 0 0 0 0 1 1 1
16
Give me 4 bytes in RAM
int a =10;
int a =400;
int a =50;
int a =-50;
17
int a = ;
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0
0 1 1 1 1 0 0 0
int a = ;
0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 1 0 0 1 0 0
0 1 1 1 0 0 0 1
int a = ;
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
int a = ;
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
18
float : Give me 4 bytes in RAM and use IEEE754 Standard to store value
float a = 10.75;
float a = 3.14;
float a = 20.158;
float a = -20.158;
19
20
21
22
float a = ;
float a = ;
float a = ;
float a = ;
float a = ;
23
24
25
26
double : give me 8 bytes in RAM
double a=10.75;
double a=20.158;
double a=-20.158;
27
28
29
30
short :
Long:
31
Array:
int a[]={1,2,3,4,5};
2.using pointer
32
a[0]
a[1]
a[2]
a[3]
a[4]
a[5]
*(a+0)
*(a+1)
*(a+2)
*(a+3)
*(a+4)
*(a+5)
33
float a[]={10.75,3.14, 20.158,-20.158,-3.14}
34
double c[]={10.75,-10.75};
35
Char a[]={‘a’,’b’,’c’, ‘d’};
36
struct node
1. 1.
{ 2. 2.
3. 3.
4. 4.
5. 5.
}; 6. 6.
struct node n1;
7. 7.
8. 8.
9. 9.
37
38
39
40
41
S.NO Fact to be checked True/ False
42
DAY 2
Start here
Do this ;
Do this;
Do this ;
#include<stdio.h>
#define MAX 10
int main()
scanf(“%d”,&firstNumber);
scanf(“%d”,&SecondNumber);
printf(“%d”,sum);
43
Object Oriented Programming
• The objects are real world entities that have properties and actions.
Pen.write();
Start here
Myobject.Dothis();
MyObject.Dothis();
MyObject.Dothis();
44
output functions
Code Warning/error/output
main(){}
int main() {}
()
{}
int a;
a();
int main()
{
int a;
}
int main()
{
int a=10;
printf(“%d”,a);
}
#include<stdio.h>
int main()
{
int a=10;
printf(“%d”,a);
}
#include<stdio.h>
int main()
{
printf(“hello”);
}
#include<stdio.h>
int main()
{
int a;
printf(“hello”);
scanf(“%d”,&a);
}
#include “stdio.h”
int main()
{
int a;
printf(“hello”);
scanf(“%d”,&a);
}
#include “stdio.h”
int main()
{
int a;
printf(“hello”);
scanf(“%d”,&a);
printf(“%d”,a);
}
45
Code Warning/error/output
#include “stdio.h”
int main()
{
printf(“%d”,4);
}
#include “stdio.h”
int main()
{
printf(“%d”,printf(“MCET”));
}
#include “stdio.h”
int main()
{
printf(“%d”,printf(“MCE”));
}
#include “stdio.h”
int main()
{
printf(“%f”,1.25);
}
#include “stdio.h”
int main()
{
printf(“%f”,1.25f);
}
#include “stdio.h”
int main()
{
puts(“Welcome”);
}
#include “stdio.h”
int main()
{
puts(puts(“Welcome”));
}
#include <stdio.h>
int main()
{
printf("%d",puts("Wel"));
}
46
input functions
Code Warning/error/output
#include “stdio.h”
int main()
{
int a;
scanf(“%d”,&a);
printf(“%d”,a);
}
#include “stdio.h”
int main()
{
char a;
scanf(“%c”,&a);
printf(“%d”,a);
}
#include “stdio.h”
int main()
{
char a;
scanf(“%c”,&a);
printf(“%d”,a);
printf(“%c”,a);
}
#include “stdio.h”
int main()
{
float a=65.5;
printf(“%f”,a);
scanf(“%f”,&a);
printf(“%f”,a);
}
#include “stdio.h”
int main()
{
double a;
scanf(“%lf”,&a);
printf(“%lf”,a);
}
#include<stdio.h>
int main()
{
Char a[5];
scanff(“%s”,a);
printf(“%s”,a);
}
47
Operators
Code Warning/error/output
#include “stdio.h”
int main()
{
int a=10,b=20,c;
int c=a+b;
printf(“%d”,c);
}
#include “stdio.h”
int main()
{
int a=10,b=20,c;
int c=a*b;
printf(“%d”,c);
}
#include “stdio.h”
int main()
{
int a=100000000;
int b=2000000;
int c;
c=a*b;
printf(“%d”,c);
}
#include “stdio.h”
int main()
{
int c,a=10, b=2;
c=a/b;
printf(“%d”,c);
}
#include “stdio.h”
int main()
{
float a=10;
int b=2;
float c;
c=a/b;
printf(“%f”,c);
}
#include “stdio.h”
int main()
{
char a=10;
char b=20;
char c;
int c=a|b;
printf(“%d”,c);}
48
c
d
c|d
c
d
c|d
c
d
c^d
c
d
c^d
c
d
c^d
49
C=10; d=20;
c
d
C&d
C=251; d=351;
c
d
C^d
c
~c
~c|1
Short C=128;
C
C<<2;
C=-128;
128
1’s compliment
+1
-128
-128>>2
1024+8+4+2+1
2048+1024+512
128+32+16+8+4+2+1
4096+1024+512
-1
50
Write the code to generate output for bitwise operations
51
52
Code Warning/error/output
int main()
{
int a;
scanf(“%d”,&a);
if(a==10)
printf(“%d”,a);
}
int main()
{
int a;
scanf(“%d”,&a);
if(a=10)
printf(“%d”,a);
}
int main()
{
int a;
scanf(“%d”,&a);
if(0)
printf(“%d”,a);
}
int main()
{
if(0+1)
printf(“hai”);
}
int main()
{
if(‘a’)
printf(“hai”);
}
int main()
{
if(‘\0’)
printf(“hai”);
}
int main()
{
if(1==2)
printf(“hai”);
else if(1!=1)
printf(“hello”);
else
printf(“vanakkam”);
}
53
Code Warning/error/output
int main()
{
if(1>>2)
printf(“hai”);
}
int main()
{
if(1>>2)
printf(“hai”);
printf(“hello”);
}
int main()
{
if(0==(0<<2))
printf(“hai”);
printf(“hello”);
}
int main()
{
if(0!=(1<<2))
printf(“hai”);
printf(“hello”);
}
int main()
{
if(4==(1<<2))
printf(“hai”);
printf(“hello”);
}
int main()
{
if(!4)
{
printf(“hai”);
printf(“hello”);
}
}
int main()
{
if(!4)
{
printf(“hai”);
printf(“hello”);
}
else
printf(“hai else”);
printf(“inevitable”);
}
Change 4 to 0 in if
54
Code Warning/error/output
int main()
{
int a;
scanf(“%d”,&a);
switch(a)
{
case 1 :
printf(“one”);
case 2 :
printf(“two”);
case 3 :
printf(“three”);
}
}
int main()
{
int a;
scanf(“%d”,&a);
switch(a)
{
case 1 :
printf(“one”);
break;
case 2 :
printf(“two”);
case 3 :
printf(“three”);
}
}
int main()
{
int a;
scanf(“%d”,&a);
switch(a)
{
case 1 :
printf(“one”); break;
case 2 :
printf(“two”); break;
case 3 :
printf(“three”);
break;
default :
printf(“no match”);
}
}
55
• Develop a c program to determine the number odd or even (use bitwise
operator in if condition)
56
Repeating code
For:
While:
Do while:
57
2 5
1
for( ; ; )
{ 3
4
}
2 5
1
for( ; ; )
{ 3
4
}
58
2 5
1
for( ; ; )
{ 3
;
4
}
2 5
for( 1 ; ; )
{ 3
; ;
;
4
}
59
for( ; ; )
for( ; ; )
60
// remove the for loop and generate same output
#include <stdio.h>
int main() {
int i;
for (i = 1; i < 11; ++i)
{
printf("%d ", i);
}
return 0;
}
61
1
while( )
{ 2
} 3
while( )
{ 2
} 3
while( )
{ 2
} 3
62
while( )
while( )
63
//remove the loop from the program
#include<stdio.h>
int main(){
int i=1;
while(i<=10){
printf("%d \n",i);
i++;
}
return 0;
}
64
do
; 1
4
; 2
; 3
} while( )
do
} while( )
do
} while( )
65
do
} while( )
66
Function
#include<stdio.h>
int firstnum,secondnum,sum,diff;
int main()
{
scanf(“%d”,&firstnum);
scanf(“%d”,&secondnum);
sum=firstnum+secondnum;
diff=firstnum-secondnum;
printf(“sum is :%d\n difference is:%d ”,sum,diff);
scanf(“%d”,&firstnum);
scanf(“%d”,&secondnum);
sum=firstnum+secondnum;
diff=firstnum-secondnum;
printf(“sum is :%d\n difference is:%d ”,sum,diff);
scanf(“%d”,&firstnum);
scanf(“%d”,&secondnum);
sum=firstnum+secondnum;
diff=firstnum-secondnum;
printf(“sum is :%d\n difference is:%d ”,sum,diff);
scanf(“%d”,&firstnum);
scanf(“%d”,&secondnum);
sum=firstnum+secondnum;
diff=firstnum-secondnum;
printf(“sum is :%d\n difference is:%d ”,sum,diff);
scanf(“%d”,&firstnum);
scanf(“%d”,&secondnum);
sum=firstnum+secondnum;
diff=firstnum-secondnum;
printf(“sum is :%d\n difference is:%d ”,sum,diff);
scanf(“%d”,&firstnum);
scanf(“%d”,&secondnum);
sum=firstnum+secondnum;
diff=firstnum-secondnum;
printf(“sum is :%d\n difference is:%d ”,sum,diff);
scanf(“%d”,&firstnum);
scanf(“%d”,&secondnum);
sum=firstnum+secondnum;
diff=firstnum-secondnum;
printf(“sum is :%d\n difference is:%d ”,sum,diff);
scanf(“%d”,&firstnum);
scanf(“%d”,&secondnum);
sum=firstnum+secondnum;
diff=firstnum-secondnum;
printf(“sum is :%d\n difference is:%d ”,sum,diff);
scanf(“%d”,&firstnum);
scanf(“%d”,&secondnum);
sum=firstnum+secondnum;
diff=firstnum-secondnum;
printf(“sum is :%d\n difference is:%d ”,sum,diff);
scanf(“%d”,&firstnum);
scanf(“%d”,&secondnum);
sum=firstnum+secondnum;
diff=firstnum-secondnum;
printf(“sum is :%d\n difference is:%d ”,sum,diff);
67
#include<stdio.h>
int firstnum, fact;
int main()
{
scanf(“%d”,&firstnum);
for(i=1;i<=firstnum;i++)
{
fact=fact*I;
}
printf(“ factorial is :%d”,fact);
scanf(“%d”,&firstnum);
for(i=1;i<=firstnum;i++)
{
fact=fact*I;
}
printf(“ factorial is :%d”,fact);
1.We try to find the code block that repeats and give name to that block
#include<stdio.h>
int firstnum.fact;
int main()
{
Suggest Name of the code block:
scanf(“%d”,&firstnum);
for(i=1;i<=firstnum;i++)
{
fact=fact*i;
}
printf(“ factorial is :%d”,fact);
void (void)
{
Paste the block of code that repeats
68
3. create a function prototype above the main
#include<stdio.h>
int firstnum, fact;
void GetNumberAndDisplayFactorial(void);
int main()
{
GetNumberAndDisplayFactorial();
}
Void GetNumberAndDisplayFactorial(void)
{
scanf(“%d”,&firstnum);
for(i=1;i<=firstnum;i++)
{
fact=fact*I;
}
printf(“ factorial is :%d”,fact);
}
69
Calling function
Called function
function prototype
arguments(actual arguments)
parameters(formal arguments)
function definition
return type
70
1. #include<stdio.h> return type of main
2. void greeting(void); protype of greeting is given in line number
3. int main()
calling function of greeting
4. {
5. greeting(); printf is called function of
6. } return type of greeting
7. void greeting(void) parameters of greeting is given in line number
8. { function definition of greeting starts in line number
9. printf(“hai”);
function definition of greeting ends in line number
10. }
greeting is called in line number
1. #include<stdio.h> return type of main
2. void display(void); protype of greeting is given in line number
3. void greeting(void); calling function of greeting
4. void main() calling function of display
5. { called function of display
6. greeting(); protype of display is given in line number
7. } printf is called function of
8. void greeting(void) return type of greeting
9. {
parameters of greeting is given in line number
10. display();
function definition of display starts in line number
11. }
function definition of display ends in line number
12. void display(void)
greeting is called in line number
13. {
14. printf(“hai”); printf is called in line number
15. } return type of display
return type of printf
1. #include<stdio.h>
2. void greeting(int a)
3. { protype of greeting is given in line number
4. display(a);
5. }
6. void display(int a)
7. {
8. printf(“%d”,a); protype of display is given in line number
9. }
10. int main()
11. {
return type of greeting
12. Int a =10;
argument type of greeting
13. greeting(a);
14. } display is called by
main is called by
argument list of main
1. #include<stdio.h> address of a in main
2. void display(int); address of a in greeting
3. void greeting(int); address of a in display
4. void main()
5. {
6. Int a=10;
7. Printf(“%d”,&a);
8. greeting(a+1);
9. printf(“%d”,a);
10. }
11. void greeting(int a)
12. {
13. Printf(“%d”,&a); output of line 8 is 10; justify
14. a=a+1;
15. display(a);
16. }
17. void display(int a)
18. {
19. Printf(“%d”,&a);
20. printf(“%d”,a);
21. }
71
RAM
37
36
35 Heap
34
33
32
31
30
29
28
int d; 27
int main() 26
{ 25
24
int a,b,c;
23 Stack
static char e; 22
short int *ptr; 21
ptr=malloc(2); 20
free(ptr); 19
18
}
17
16
15
14
13
12
11
10
9
global/static
8
7
6
5
4
3
2
code
1
0
72
int main()
{
int a,b,c;
}
int d;
int main()
{
static char e;
int a,b,c;
}
1. #include<stdio.h>
2. void display(int);
3. void greeting(int);
4. void main()
5. {
6. Int a=10;
7. Printf(“%d”,&a);
8. greeting(a+1);
9. printf(“%d”,a);
10. }
11. void greeting(int a)
12. {
13. Printf(“%d”,&a);
14. a=a+1;
15. display(a);
16. }
17. void display(int a)
18. {
19. Printf(“%d”,&a);
20. printf(“%d”,a);
21. }
73
1. #include<stdio.h>
2. int fact(int);
3. void main()
4. {
5. int factorial=fact(3);
6. printf(“%d”, factorial);
7. }
8. int fact(int n)
9. {
10. if(n==0)
11. return 1;
12. return n*fact(n-1);
13. }
74
1. #include<stdio.h>
2. int fact(int);
3. void main()
4. {
5. int sumn=sum(3);
6. printf(“%d”, sumn);
7. }
8. int sum(int n)
9. {
10. if(n==1)
11. return 1;
12. return n+sum(n-1);
13. }
75
#include <stdio.h>
int fun(int n)
{
if (n == 4)
return n;
else return 2*fun(n+1);
}
int main()
{
printf("%d", fun(2));
return 0;
}
76
if n=25 what will be printed?
void fun(int n)
{
if (n == 0)
return;
printf("%d", n%2);
fun(n/2);
}
#include<stdio.h>
void print(int n)
{
if (n > 4000)
return;
printf("%d ", n);
print(2*n);
printf("%d ", n);
}
int main()
{
print(1000);
getchar();
return 0;
}
77
Pointers
*
&
int a=10;
float b=10.75;
char c=10;
double d=10.75;
(int/float/char/double)
&a
&b
&c
&d
78
Address type Pointer Declaration
To store address of int
79
50 54 60 67 70 77 80 87
200 50 60 70
a b c d
50 54 60 67 70 77 80 87
3.14 50 60 70
a b c d
80
50 57 60 67 70 77 80 87
3.14 50 60 70
a b c d
81
int a[]={1,2,3,4}; // a[i] *(a+i) [i]a
82
Char *ptr=(char*)a;
83
DYNAMIC MEMORY ALLOCATION
malloc:
calloc:
realloc:
free
84
37
36
35 Heap
34
33
32
31
30
29
28
27
26
25
24
23 Stack
22
21
20
19
18
17
16
15
14
13
12
11
10
9
global/static
8
7
6
5
4
3
2
code
1
0
85
36
35
34
33
32
31
30
29 Heap
28
27
26
25
24
23
22
21
20
19
18
17
Stack
16
15
14
13
12
11
10
9
global/static
8
7
6
5
4
3
2
code
1
0
86
36
35
34
33
32
31
30
29 Heap
28
27
26
25
24
23
22
21
20
19
18
17
Stack
16
15
14
13
12
11
10
9
global/static
8
7
6
5
4
3
2
code
1
0
87
36
35
34
33
32
31
30
29 Heap
28
27
26
25
24
23
22
21
20
19
18
17
Stack
16
15
14
13
12
11
10
9
global/static
8
7
6
5
4
3
2
code
1
0
88
36
35
34
33
32
31
30
29 Heap
28
27
26
25
24
23
22
21
20
19
18
17
Stack
16
15
14
13
12
11
10
9
global/static
8
7
6
5
4
3
2
code
1
0
89
36
35
34
33
32
31
30
29 Heap
28
27
26
25
24
23
22
21
20
19
18
17
Stack
16
15
14
13
12
11
10
9
global/static
8
7
6
5
4
3
2
code
1
0
90
36
35
34
33
32
31
30
29 Heap
28
27
26
25
24
23
22
21
20
19
18
17
Stack
16
15
14
13
12
11
10
9
global/static
8
7
6
5
4
3
2
code
1
0
91