0% found this document useful (0 votes)
0 views

Functions & Storage Classes _ DPP 01

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)
0 views

Functions & Storage Classes _ DPP 01

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/ 5

GATE

C Programming
Function and Storage Classes DPP : 1

Q1 Consider the following program: }


#include<stdio.h> Which of the following is correct?
int f2(int a) (A) Compilation error
{ (B) “GATE Wallah” will be printed infinite number
int b=0; of times.
b=b+5; (C) “GATE Wallah” will be printed 5 times.
return a*b; (D) “GATE Wallah” will be printed 4 times.
}
Q3 Consider the following program.
int f1(int a)
#include<stdio.h>
{
void f(int n)
int b;
{
b=f2(a);
switch(n<<1+n)
return a*b;
{
}
default: printf("Sresth");
int main()
case 4: printf("Parakram");
{
case 3: printf("2024");
int i, a=5, b=4;
break;
for(i=0;i<2;i++)
case 2: printf("2025");
{
}
b-=f1(a)-f2(a);
}
printf("%d\t", b);
int main()
}
{
return 0;
f(1);
}
return 0;
The sum of the printed values is ____________
}
Q2 Consider the following program: The output is-
#include<stdio.h> (A) Parakram2024
void print(int n) (B) SresthParakram2024
{ (C) Parakram
for(n++;n++;n++) (D) Sresth2025
printf("GATE Wallah");
Q4 Consider the following program:
}
#include<stdio.h>
int main()
void f()
{
{
void print();
int x;
void print();
x=10<5?printf("%d",
print(-9);
printf("GATE")):printf("")
return 0;
printf("2024"):printf("%d", printf("Wallah

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf?session_id=tj6c4cukr3eq3grnfi8ihw2kh 1/5
6/17/24, 7:06 PM GATE_C Programming_DPP 1

GATE

Parakram")); printf("%d", f(1,2));


} return 0;
int main() }
{ The value printed is _______.
f();
Q6 Consider the following program:
return 0;
#include <stdio.h>
}
int r(int num)
The output is
{
(A) GATE2024
return --num;
(B) Wallah Parakram15
}
(C) GATEWallah Parakram4
int main()
(D) GATE4
{
Q5 Consider the following program: int n=4;
#include<stdio.h> for (r(n);r(n++);r(--n))
int f(int b, int a) printf("%d\t",r(--n));
{ return 0;
int x; }
x=a<<b; The output is-
b=x*a--; (A) 1 2 3
return a+b-x; (B) 1 2 3 4
} (C) 3 2 1
int main() (D) 4 3 2 1
{

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf?session_id=tj6c4cukr3eq3grnfi8ihw2kh 2/5
GATE

Answer Key
Q1 -292~-293 Q4 (B)

Q2 (D) Q5 5~4

Q3 (A) Q6 (C)

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf?session_id=tj6c4cukr3eq3grnfi8ihw2kh 3/5
GATE

Hints & Solutions


Q1 Text Solution: return 0;
For i=0: }
f1(5): print(-9){//n=9
Line 1: int b; for(n++; n++ ;n++)
Line 2: b=f2(5);//b=25 -9 -8 ->printf() is executed -7
Line 3:return 5*25; //return 125 to main(). -6 ->printf() is executed -5
f2(5): -4 ->printf() is executed -3
Line 1: int b=0; -2 ->printf() is executed -1
Line 2: b=b+5;//b=5 0 -> Loop terminates
Line 3: return 5*5;//return 25 to f1.Go to Line 3 of }
f1(5) “GATE Wallah” will be printed four times.
f2(5):
Q3 Text Solution:
Line 1: int b=0;
f(1):
Line 2: b=b+5;//b=5
n=1;
Line 3: return 5*5;//return 25 to main().
switch(n<<1+n)
b in main() is updated to: b=b-f1(a)+f2(a)=4- {
125+25=-96.
//switch(1<<2) i.e switch(4)
For i=1:
default: printf("Sresth");
f1(5):
case 4: printf("Parakram");
Line 1: int b;
//case 4 is executed.
Line 2: b=f2(5);//b=25
//since no break is there case 3 will also be
Line 3:return 5*25; //return 125 to main().
executed.
f2(5):
case 3: printf("2024");
Line 1: int b=0;
break;
Line 2: b=b+5;//b=5
case 2: printf("2025");
Line 3: return 5*5;//return 25 to f1.Go to Line 3 of
}
f1(5)
Output: Parakram2024
f2(5):
Q4 Text Solution:
Line 1: int b=0;
f():
Line 2: b=b+5;//b=5
x = 10<5?printf(“%d”, printf(“GATE”));
Line 3: return 5*5;//return 25 to main().
printf(“”)?printf(“2024”);
b in main() is updated to: b=b-f1(a)+f2(a)=-96
printf(“%d”, printf(“Wallah Parakram”));
-125+25=-196.
10<5 is FALSE. So, printf("") is evaluated. It prints
Output is: -96 -196
nothing and hence returns 0.
Sum= -292
0 means FALSE. So, printf("%d",printf("Wallah
Q2 Text Solution:
Parakram")) is evaluated.
int main()
Output: Wallah Parakram15
{
Q5 Text Solution:
void print();//No compilation error
f(1,2):
void print();//No compilation error
b = 1, a = 2;
print(-9); //print(-9) is called.

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf?session_id=tj6c4cukr3eq3grnfi8ihw2kh 4/5
6/17/24, 7:06 PM GATE_C Programming_DPP 1

GATE

x = a <<b; //x = 2 << 1 = 4 r(--n) or r(3) is called.


b = x*a--;//b = 4*2 = 8. After this, a is r(n++)or r(3)=2->TRUE// Condition check
decremented to 1. n is incremented to 4.
return a + b - x; // return 1+8-4 i.e. return 5. printf("%d\t",r(--n));// printf("%d\t",r(3))
main(): //2 is printed.
printf("%d", f(1,2));//5 is printed. r(--n) or r(2) is called.
Output: 5 r(n++)or r(2)=1->TRUE// Condition check

Q6 Text Solution: n is incremented to 3.

r(4)=3. //Intialization printf("%d\t",r(--n));// printf("%d\t",r(2))


//1 is printed.
r(n++)or r(4)=3->TRUE// Condition check
r(--n) or r(0) is called.
n is incremented to 5.
printf("%d\t",r(--n));// printf("%d\t",r(4)) r(n++)or r(1)=0->FALSE//Loop terminates.

//3 is printed. Output: 3 2 1

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf?session_id=tj6c4cukr3eq3grnfi8ihw2kh 5/5

You might also like