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

Functions & storage classes _ DPP 01 __ Parakram GATE 2024 Computer Science Weekend (English)

The document contains a series of programming questions and answers related to the C programming language, focusing on functions, control structures, and output. It includes multiple-choice questions (MCQs) with correct answers and explanations for each question. Additionally, it provides hints and solutions for understanding the logic behind the programming problems presented.

Uploaded by

rohitdummyy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Functions & storage classes _ DPP 01 __ Parakram GATE 2024 Computer Science Weekend (English)

The document contains a series of programming questions and answers related to the C programming language, focusing on functions, control structures, and output. It includes multiple-choice questions (MCQs) with correct answers and explanations for each question. Additionally, it provides hints and solutions for understanding the logic behind the programming problems presented.

Uploaded by

rohitdummyy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1

Branch : CSE & IT Batch:English


Programming in C
Function DPP-01

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

[MCQ] f(1);
2. Consider the following program: return 0;
#include<stdio.h> }
void print(int n){ The output is-
for(n++;n++;n++) (a) Parakram2024
printf("GATE Wallah"); (b) SresthParakram2024
} (c) Parakram
int main(){ (d) Sresth2025
void print();
void print();
2

[MCQ] int main(){


4. Consider the following program: printf("%d", f(1,2));
#include<stdio.h> return 0;
void f(){ }
int x; The value printed is _______.
x=10<5?printf("%d",
printf("GATE")):printf("")?printf("2024"):printf("%d [MCQ]
",printf("Wallah Parakram")); 6. Consider the following program:
} #include <stdio.h>
int main(){ int r(int num){
f(); return --num;
return 0; }
}
int main(){
The output is-
int n=4;
(a) GATE2024
for (r(n);r(n++);r(--n))
(b) Wallah Parakram15
(c) GATEWallah Parakram4 printf("%d\t",r(--n));
(d) GATE4 return 0;
}
[NAT] The output is-
5. Consider the following program:
(a) 1 2 3
#include<stdio.h>
(b) 1 2 3 4
int f(int b, int a){
int x; (c) 3 2 1
x=a<<b; (d) 4 3 2 1
b=x*a--;
return a+b-x;
}
3

Answer Key
1. (–292) 4. (b)
2. (d) 5. (5)
3. (a) 6. (c)
4

Hints and Solutions

1. (–292) 2. (d)
For i=0: int main(){
f1(5): void print();//No compilation error
Line 1: int b; void print();//No compilation error
Line 2: b=f2(5);//b=25 print(-9); //print(-9) is called.
Line 3:return 5*25; //return 125 to main(). return 0;
f2(5): }
Line 1: int b=0; print(-9){//n=9
Line 2: b=b+5;//b=5
for(n++; n++ ;n++)
Line 3: return 5*5;//return 25 to f1.Go to Line 3 of
-9 -8 ->printf() is executed -7
f1(5)
f2(5): -6 ->printf() is executed -5

Line 1: int b=0; -4 ->printf() is executed -3

Line 2: b=b+5;//b=5 -2 ->printf() is executed -1


Line 3: return 5*5;//return 25 to main(). 0 -> Loop terminates
b in main() is updated to: b=b-f1(a)+f2(a)=4- }
125+25=-96. “GATE Wallah” will be printed four times.
For i=1:
f1(5): 3. (a)
f(1):
Line 1: int b;
n=1;
Line 2: b=f2(5);//b=25
Line 3:return 5*25; //return 125 to main(). switch(n<<1+n){

f2(5): //switch(1<<2) i.e switch(4)


Line 1: int b=0; default: printf("Sresth");
Line 2: b=b+5;//b=5 case 4: printf("Parakram");
Line 3: return 5*5;//return 25 to f1.Go to Line 3 of //case 4 is executed.
f1(5) //since no break is there case 3 will also be
f2(5): executed.
Line 1: int b=0; case 3: printf("2024");
Line 2: b=b+5;//b=5 break;
Line 3: return 5*5;//return 25 to main(). case 2: printf("2025");
b in main() is updated to: b=b-f1(a)+f2(a)=-96 }
-125+25=-196.
Output: Parakram2024
Output is: -96 -196
Sum= -292
5

4. (b) 6. (c)
f(): r(4)=3. //Intialization
x = 10<5?printf(“%d”, printf(“GATE”)); r(n++)or r(4)=3->TRUE// Condition check
n is incremented to 5.
printf(“”)?printf(“2024”);
printf("%d\t",r(--n));// printf("%d\t",r(4))
printf(“%d”, printf(“Wallah Parakram”)); //3 is printed.
10<5 is FALSE. So, printf("") is evaluated. It prints r(--n) or r(3) is called.
nothing and hence returns 0. r(n++)or r(3)=2->TRUE// Condition check
0 means FALSE. So, printf("%d",printf("Wallah n is incremented to 4.
Parakram")) is evaluated.
printf("%d\t",r(--n));// printf("%d\t",r(3))
Output: Wallah Parakram15
//2 is printed.

5. (5) r(--n) or r(2) is called.


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

For more questions, kindly visit the library section: Link for app: https://physicswallah.live/tabs/tabs/library-tab
For more questions, kindly visit the library section: Link for web: https://links.physicswallah.live/vyJw
Any issue with DPP, please report by clicking here- https://forms.gle/t2SzQVvQcs638c4r5

PW Mobile APP: https://play.google.com/store/apps/details?id=xyz.penpencil.physicswala


For PW Website: https://www.physicswallah.live/contact-us

You might also like