Question 1
Consider the following code:
int a, b, c = 0;
void prtFun(void);
void main()
{
static int a = 1;
prtFun();
a += 1;
prtFun() printf("\n %d %d ", a, b);
}
void prtFun(void)
{
static int a = 2;
int b = 1;
a += ++b;
printf("\n %d %d ", a, b);
}
What output will be generated by the given code d\\segment if:
Line 1 is replaced by “auto int a = 1;”
Line 2 is replaced by “register int a = 2;” (GATE CS 2012)
3 1
4 1
4 2
4 2
6 1
6 1
4 2
6 2
2 0
4 2
4 2
2 0
Question 2
#include <stdio.h>
char *fun()
{
static char arr[1024];
return arr;
}
int main()
{
char *str = "geeksforgeeks";
strcpy(fun(), str);
str = fun();
strcpy(str, "geeksquiz");
printf("%s", fun());
return 0;
}
Question 3
In C, static storage class cannot be used with:
Global variable
Function parameter
Function name
Local variable
Question 4
If only one memory location is to be reserved for a class variable, no matter how many objects are instantiated, then the variable should be declared as
extern
static
volatile
const
Question 5
What is the output of the following program?
#include
int tmp=20;
main( )
{
printf("%d ",tmp);
func( );
printf("%d ",tmp);
}
func( )
{
static int tmp=10;
printf("%d ",tmp);
}
20 10 10
20 10 20
20 20 20
10 10 10
Question 6
Which of the following is not a storage class specifier in C?
auto
register
static
extern
volatile
Question 7
Consider the following pseudocode:
x : integer := 1
y : integer := 2
procedure add
x := x + y
procedure second (P: procedure)
x : integer := 2
P()
procedure first
y : integer := 3
second(add)
first()
write_integer (x)
What does it print if the language uses dynamic scoping with deepbinding?
2
3
4
5
Question 8
Consider the following code fragment void foo(int x, int y) { x+=y; y+=x; } main() { int x=5.5; foo(x,x); } What is the final value of x in both call by value and call by reference, respectively?
5 and 16
5 and 12
5 and 20
12 and 20
Question 9
The following program
main()
{
inc(); inc(); inc();
}
inc()
{
static int x;
printf("%d", ++x);
}
prints 012
prints 123
prints 3 consecutive, but unpredictable numbers
prints 111
Question 10
There are 31 questions to complete.