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

Functions and Storage Class: #Include Int Int Int Int Return Int Void

The document contains 16 multiple choice questions about functions and storage classes in C programming. It tests knowledge of variable scope, static variables, passing arguments to functions, recursion, and more. The questions have a variety of correct answers ranging from simple ones like addition to more complex recursive functions.

Uploaded by

mayande rohini
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)
84 views

Functions and Storage Class: #Include Int Int Int Int Return Int Void

The document contains 16 multiple choice questions about functions and storage classes in C programming. It tests knowledge of variable scope, static variables, passing arguments to functions, recursion, and more. The questions have a variety of correct answers ranging from simple ones like addition to more complex recursive functions.

Uploaded by

mayande rohini
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/ 11

Functions And Storage Class

1.
#include <stdio.h>
int num;
int function(int n)
{
int num = 10;
return num;
}
int main(void)
{
printf("%d %d\n", num, function(20));
return 0;
}

A. 10 0
B. 20 0
C. 0 10
D. 0 20

Answer: C

2.
#include <stdio.h>
int main(void)
{
static int val = 8;
if(val--) main();
printf("%d ", val);
return 0;
}

A. -1 -1 -1 -1 -1 -1 -1 -1 -1
B. 0 0 0 0 0 0 0 0 0
C. -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
D. 0 0 0 0 0 0 0 0 0 ...

Answer: A

February 2020 – Augest 2020 1


Functions And Storage Class
3.
#include <stdio.h>
int n2 = 11, n1 = 12;
int test(int n1, int n2)
{
int r1, r2, r3;
r1 = n1 + n2; r3 = n1 - n2; r2 = n1 * n2;
return r1, r2, r3;
}
int main(void)
{
int n1 = 11, n2 = 12;
printf(" %d ", test(printf("Sunbeam Pune"),
printf("Sunbeam Karad")));
printf("%d %d\n", n1, n2);
return 0;
}

A. Sunbeam KaradSunbeam Pune -1 11 12


B. Sunbeam Karad Sunbeam Pune -1 11 12
C. Sunbeam KaradSunbeam Pune 23 11 12
D. Sunbeam Karad Sunbeam Pune 23 11 12

Answer: A

4.
#include <stdio.h>
int main(void)
{
register char reg = 20;
char *ptr_reg = NULL;

ptr_reg = &reg;
*ptr_reg = 40;

printf("%d ", reg);


return 0;
}

February 2020 – Augest 2020 2


Functions And Storage Class
A. 20
B. 40
C. Compile time error
D. Run time error
Answer: C

5.
#include <stdio.h>
int var = 1;
int main(void)
{
auto int var, var1; var = init();
for(var1 = 1 ; var1 <= 3 ; var1++)
{
printf("%d ", first(var));
printf("%d ", last(var));
}
return 0;
}
int init(void)
{
return (var);
}
int first(int var)
{
return var = var++;
}
int last(int var1)
{
static int var = 5;
return var1 = var--;
}
A. 1 5 1 4 1 3
B. 1 5 1 5 1 5
C. 1 5 2 5 3 5
D. 1 5 2 4 3 3

Answer: A

February 2020 – Augest 2020 3


Functions And Storage Class
6.
#include <stdio.h>
static char char1 = 'A';
extern char char2 = 'B';
register char char3 = 'C';
void mystorage(void)
{
printf("%c %c %c\n", char1, char2, char3);
}
int main(void)
{
printf("%c %c %c\n", char1, char2, char3);
mystorage();
return 0;
}

A. A B C
A B C

B. Compile time error -


static variable can not be declared globally

C. Compile time error -


extern variable can not be declared globally

D. Compile time error -


register variable can not be declared globally

Answer: D

7.
#include <stdio.h>
int demo(char p1, char p2)
{
char p3;
p3 = ~p1 + ~p2;
return p3;
}

February 2020 – Augest 2020 4


Functions And Storage Class
int main(void)
{
char p1 = 255, p2 = 256;

char p3 = demo(~p1++, ~p2--);


printf("%d %d %d\n", p1, p2, p3);

return 0;
}
A. -1 -1 0
B. -1 0 -1
C. 0 -1 -1
D. None of the above

Answer: C

8.
#include <stdio.h>
int rec(int);
int main(void)
{
static int val = 8;
printf("%d ", rec(val));
return 0;
}
int rec(int val)
{
static int sal = 10;
if(val)
return sal + rec(val--);
}

A. 80
B. Compile time error
C. Runtime time error(exit status -1)
D. None of the above

Answer: C

February 2020 – Augest 2020 5


Functions And Storage Class
9.
#include <stdio.h>
int i = 0;
int main(void)
{
auto int i = 1;
printf("%d ", i);
{
int i = 2;
printf("%d ", i);
{
i += 1;
printf("%d ", i);
}
printf("%d ", i);
}
printf("%d ", i);
return 0;
}

A. 0 1 2 2 0
B. 1 2 3 2 1
C. 1 2 3 3 1
D. 0 1 2 1 0

Answer: C

10.
#include <stdio.h>
int rec(int);
int main(void)
{
int num =3;
printf("%d\n", rec(num));

return 0;
}

February 2020 – Augest 2020 6


Functions And Storage Class
int rec(int n)
{
if(n < 1)
return n + 1;
return n + rec(n-1) + rec(n-2);
}

A. 5
B. 11
C. 10
D. 9
Answer: C

11.
#include <stdio.h>
int my = 0;
int myset(int my)
{
printf("%d ", my++);
return my = my <= 2 ? 5 : 0;
}
int main(void)
{
int my = 5;

myset( my/2 ); printf("%d ", my);


myset( my=my/2 ); printf("%d ", my);
my = myset( my/2 ); printf("%d ", my);

return 0;
}

A. 3 5 3 2 2 5
B. 2 5 2 2 1 5
C. 2 3 2 2 2 5
D. 3 3 3 2 1 5

Answer: B

February 2020 – Augest 2020 7


Functions And Storage Class
12.
#include <stdio.h>
int ext = 30;
int main(void)
{
extern int ext;
printf("Ext = %d ", ext);
extfun();
return 0;
}
int ext = 10;
int extfun(void)
{
int ext = 20;
printf("%d\n",ext);
}
A. Ext = 10 20
B. Ext = 30 20
C. Compile time error
D. Run time error
Answer: C

13.
#include <stdio.h>
int no1 = 17, no2 = 71;
void swapping(void)
{
int temp = no2; no2 = no1; no1 = temp;
return ;
}
int main(void)
{
int no1 = 17, no2 = 71;
printf("%d %d ", no1 , no2);
swapping();
printf("%d %d\n", no1, no2);
return 0;
}

February 2020 – Augest 2020 8


Functions And Storage Class
A. 17 17 17 17
B. 17 71 17 71
C. 71 17 71 17
D. 71 71 71 71

Answer: B

14.
#include <stdio.h>
int testDemo(int, int);
int main(void)
{
int you = 64, me = 32;

int we = testDemo(you, me);


printf("%d %d %d\n", me, you, we);
return 0;
}
int testDemo(int me, int you)
{
me = me + you;
return me - you;
you = you - me;
return me + you;
}

A. 32 64 32
B. 64 64 32
C. 64 32 64
D. 32 64 64

Answer: D

February 2020 – Augest 2020 9


Functions And Storage Class
15.
#include <stdio.h>
int num = 7;
int function(void)
{
static int num = 9;

printf("%d ", num); num -=2;


return num;
}
int main(void)
{
while(function() >= 0);

return 0;
}

A. 9 9 9 9 9
B. 9 7 5 3 1
C. 7 7 7 7 7
D. 7 5 3 1

Answer: B

16.
#include <stdio.h>
int function(int arg)
{
static int num = 6;
if(num <= 1)
return num;
return arg + function(arg -= num--);
}
int main(void)
{
printf("return = %d\n", function(16));
return 0;
}

February 2020 – Augest 2020 10


Functions And Storage Class
A. 29
B. 25
C. 11
D. None of the above

Answer: C

February 2020 – Augest 2020 11

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy