Question 1
int arr[50] = {0,1,2,[47]=47,48,49};
Question 2
#include "stdio.h"
void fun(int n)
{
int idx;
int arr1[n] = {0};
int arr2[n];
for (idx=0; idx<n; idx++)
arr2[idx] = 0;
}
int main()
{
fun(4);
return 0;
}
Question 3
#include "stdio.h"
int size = 4;
int arr[size];
int main()
{
if(arr[0])
printf("Initialized to ZERO");
else
printf("Not initialized to ZERO");
return 0;
}
Question 4
Pick the best statement for the following program snippet:
#include <stdio.h>
int main()
{
int var; /*Suppose address of var is 2000 */
void *ptr = &var;
*ptr = 5;
printf("var=%d and *ptr=%d",var,*ptr);
return 0;
}
It will print “var=5 and *ptr=2000”
It will print “var=5 and *ptr=5”
It will print “var=5 and *ptr=XYZ” where XYZ is some random address
Compile error
Question 5
#include "stdio.h"
void foo(void)
{
static int staticVar;
staticVar++;
printf("foo: %d\\n",staticVar);
}
void bar(void)
{
static int staticVar;
staticVar++;
printf("bar: %d\\n",staticVar);
}
int main()
{
foo(), bar(), foo();
return 0;
}
Question 6
Consider the following C program:
#include <stdio.h>
typedef struct
{
char *a;
char *b;
} t;
void f1(t s);
void f2(t *p);
main()
{
static t s = {"A", "B"};
printf ("%s %s\n", s.a, s.b);
f1(s);
printf ("%s %s\n", s.a, s.b);
f2(&s);
}
void f1(t s)
{
s.a = "U";
s.b = "V";
printf ("%s %s\n", s.a, s.b);
return;
}
void f2(t *p)
{
p -> a = "V";
p -> b = "W";
printf("%s %s\n", p -> a, p -> b);
return;
}
What is the output generated by the program ?
A B U V V W V W
A B U V A B V W
A B U V U V V W
A B U V V W U V
There are 6 questions to complete.