0% found this document useful (0 votes)
11 views91 pages

C Fundamentals Learners Handbook

The document outlines a comprehensive schedule for a programming course focused on C language fundamentals, spanning six days. It includes topics such as computer hardware, software, data types, control statements, functions, and memory management, with specific time allocations for each session. Additionally, it features exercises, assessments, and recap sessions to reinforce learning.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views91 pages

C Fundamentals Learners Handbook

The document outlines a comprehensive schedule for a programming course focused on C language fundamentals, spanning six days. It includes topics such as computer hardware, software, data types, control statements, functions, and memory management, with specific time allocations for each session. Additionally, it features exercises, assessments, and recap sessions to reinforce learning.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 91

Name :

Roll No :
MODULE I
Strong Foundation.
Fundamentals of Programming and problem solving

Time
S.No Topic Time Day
Duration

Computer hardware 20 Min 09.00 to 09.20


1.
Software 20 Min 09.20 to 09.40
2.
Language of computers 20 Min 09.40 to 10.00
3.
C programming language history 20 Min 10.00 to 10.20
4.
Day 1
Hand book work 20 Min 10.20 to 10.45
5.
Data types in C 2 Hours 11.05 to 01.05
6.
Solving problems in data types 3 Hours 02.05 to 05.00
7.
Feedback session 20 min 05.00 to 05.20
8.
Recap and pop and oops 1Hour 09.00 to 10.00
9.
Input functions 1Hour 10.00 to 10.30
10.
output functions 1 hour 10.30 to 10.45
11.
Day 2
Operators 2 hour 11.05 to 01.05
12.
Control statements 1 hour 02.05 to 03.05
13.
Programming exercise 2.15 hour 03.05 to 05.20
14.
For Loop 40 min 09.00 to 09.40
15.
While loop 1 hour 09.40 to 10.40
16.
Do while 1 hour 11.05 to 12.05 Day 3
17.
Storage class 1 hour 12.05 to 01.05
18.
Problem solving 3 hours 02.05 to 05.00
19.

2
S
Time
.
Topic Time Day
N Duration
o
20. Recap 1 hour 09.00 to 10.00

21. Functions 1 hour 10.00 to 11.00

22. Examples 1 hour 11.10 to 12.00


Day 4
23. Lap Sessions 1 hour 12.00 to 01.00

24. Recursive function 1 hour 02.00 to 03.00

25. Problem solving 2 hours 03.00 to 05.00

26. Recap 40 min 09.00 to 09.50

27. Array 1 hour 09.50 to 10.40

28. Pointers 1 hour 11.05 to 12.05


Day 5
29. Pointer arithmetic 1 hour 12.05 to 01.00

30. MCQ solving 3 hour 02.00 to 05.00

31. Assessment 1 hour 05.00 to 06.00

32. Viewing each byte of memory 1 hour 09.00 to 10.00

33. Pointer type conversion 1 hour 10.00 to 11.00

34. MCQ 1 hour 11.10 to 12.10


Day 6
35. SATACK and HEAP 1 hour 12.10 to 01.10

36. Dynamic memory allocation 2 hour 02.10 to 04.10

37. Exercise 1 hour 04.10 to 05.10

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

Select the software category of Ms Paint

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

0011 1110 0000 0101

Binary 0000 0110 0000 0011

0000 0000 1000 0000

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 The instructions will be loaded into RAM


o The instructions will be running in the Hard disc itself
Other than the syntax you need to know

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 Learning any programming language is analogous to learning any other foreign


language
o First you should know the letters supported by that language (alphabets
numbers etc)

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

Start execution இங் கே செயல் படுத்தலலத் main(){


here சதொடங் குங் ேள்

give me four எனே்கு நொன்கு லபட்டுேலளே் int a;


bytes and name சேொடுத்து அதற் கு ‘a’ என
that as a; சபயரிடுங் ேள்

get input from scanf


user

show output to printf


user

Complete the இங் கே செயல் படுத்தலல }


execution here முடிே்ேவும்

13
DATA TYPES IN C

char-Give me one byte of memory in RAM and name that as ‘a’

char a;

char b= 65;

char c1= 127;

char a= 10;

Ones compliment

Ones compliment + 1= twos compliment

Unsigned char a=255;

signed char a=254;

14
char a=-1;

signed char a=-20;

unsigned char a=1;

unsigned char a=2;

unsigned char a=4;

unsigned char a=8;

unsigned char a=16;

unsigned char a=32;

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

Accessing the member of array:

1.using array name

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

Char a[]={‘a’,’b’,’c’, ‘d’,’\0’};

char c[]= “MCET”;

char a[]= “abc”;

36
struct node
1. 1.

{ 2. 2.
3. 3.
4. 4.
5. 5.
}; 6. 6.
struct node n1;
7. 7.
8. 8.

9. 9.

struct student 10. 10.


{ 11. 11.
12. 12.
13. 13.
14. 14.
15. 15.
};
struct student ramesh; 16. 16.
17. 17.
18. 18.
19. 19.
20. 20.
21. 21.
22. 22.
23. 23.
24. 24.
25. 25.
26. 26.
27. 27.
28. 28.
29. 29.
30. 30.
31. 31.

Accessing structure element :

1.using structure name(dot operator)

2.using pointers(arrow operator)

37
38
39
40
41
S.NO Fact to be checked True/ False

1. Computer is general purpose machine

The PCB board which provides seating and interconnection of


2.
processor is called as mother board
3. RAM is non volatile

4. Harddisc is non volatile

5. Regsters are volatile

6. Everything inside the memory is binary

7. Computers are designed to understand natural language

8. Machine dependent language is high level language

9. Char occupies one byte in ram

10. Short int occupies 2 bytes in RAM

11. Int occupies 2 bytes in 16 bit processor

12. Int occupies 4 bytes in 32 bit processor

13. Int occupies 8 bytes in 64 bit processor

14. Float occupies 2 bytes in 16 bit processor

15. Float occupies 4 bytes in 32 bit processor

16. float occupies 8 bytes in 64 bit processor

17. Double occupies 8 bytes in 64 bit processor

18. Array elements occupy contiguous memory location

19. Structure elements occupy contiguous memory location

20. MSB of float is for sign

If LSB of any unsigned number is 1 then the number is EVEN


21.
number
If LSB of any signed number is 1 then the number is EVEN
22.
number

42
DAY 2

Procedure oriented Programming


Before executing do this processing steps;

Start here

Do this ;

Do this;

Do this ;

#include<stdio.h>

#define MAX 10

int main()

int firstNumber, SecondNumber,Sum;

scanf(“%d”,&firstNumber);

scanf(“%d”,&SecondNumber);

Sum= firstNumber+ SecondNumber;

printf(“%d”,sum);

43
Object Oriented Programming
• The objects are real world entities that have properties and actions.

Object name Property Action


Pen
Duster
Watch
mobile

Pen.write();

Before executing do this processing steps;

Start here

Myobject.Dothis();

MyObject.Dothis();

MyObject.Dothis();

• In C we can combine elements of same type into a single entity using


__________________ .
• we can combine elements of different type into a single entity using
___________________.
• we don’t have a mechanism to combine attributes ( ) and
methods ( ).

Is it possible to create object in c?

It is possible to create objects in programming language “c with class”

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

unsigned short c=65535;

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)

• Develop a c program to determine the number odd or even (use


modulo operator in if condition)

56
Repeating code

Develop a c code to Print “hello world” thousand times in console.

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

//Use (i - -) inside the condition


#include<stdio.h>
int main(){
int i= ;
while(i ){
printf("%d \n",i);
}
return 0;
}

//Use (- -i) inside the condition


#include<stdio.h>
int main(){
int i= ;
while( ){
printf("%d \n",i);
}
return 0;
}

64
do

; 1
4
; 2

; 3

} while( )

do

} while( )

do

} while( )

65
do

} while( )

Code snippet output


int i = 0;
do {
printf("%d\n", i);
i++;
}while (i < 5);
int i = 5;
do {
printf("%d\n", i);
i++;
}while (i < 5);
int i = 0;
do {
printf("%d\n", i);
i++;
}while (i != -1);
int i = 0;
do {
printf("%d\n", i);
i--;
}while (i !=0);

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

Steps to create function:

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

2. decide return type argument list and create function definition:

Returntype Functionname ( Formal arguments ) { }

1.with return type and with argument


2.with return type and without argument
3.without return type and with argument
4.without return type and without argument

Suggested function name

void (void)

{
Paste the block of code that repeats

68
3. create a function prototype above the main

Returntype Functionname ( Parameters datatype list ) ;

4. call function inside main

Functionname ( Actual Argument ) ;


list

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

predict the value of fun(4, 3)


int fun(int x, int y)
{
if (x == 0)
return y;
return fun(x - 1, x + y);
}

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;

How you will read value it is address of

(int/float/char/double)

&a

&b

&c

&d

78
Address type Pointer Declaration
To store address of int

To store address of float

To store address of char

To store address of double

To store address of struct

To store an address that does not


have any data type

If you dereference an integer pointer points to location(200) it


reads content of the byte address ______,_______,______,____
in 32 bit processor.

If you dereference a char pointer points to location(300) it


reads content of the byte address ______,_______,______,____
in 32 bit processor.

If you dereference a float pointer points to location(400) it


reads content of the byte address ______,_______,______,____
in 32 bit processor.

If you dereference a double pointer points to location(500) it


reads content of the byte address from ______ to ____ in 32 bit
processor.

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

If a char ‘a’ is at memory location 200 and char*ptr=&a; ptr+1


will be ______

If a float ‘3.14’ is at memory location 200 and float*ptr=&a;


ptr+1 will be ______

If a double ‘3.14’ is at memory location 200 and double


*ptr=&a; ptr+1 will be ______

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

You might also like