Question 1
#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 3
#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 4
#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 5
#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;
}
Question 6
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;
}
There are 6 questions to complete.