Question 1
In the following program snippet, both s1 and s2 would be variables of structure type defined as below and there won't be any compilation issue.
typedef struct Student
{
int rollno;
int total;
} Student;
Student s1;
struct Student s2;
Both s1 and s2 are valid variables of the same structure type, and the code compiles without any error
s1 is valid, but s2 causes a compilation error because the struct tag name and typedef name cannot be the same.
s2 is valid, but s1 causes a compilation error because Student can only be used with the struct keyword
The code compiles, but s1 and s2 are of different types because typedef creates a new unrelated type.
Question 2
#include "stdio.h"
int * arrPtr[5];
int main()
{
if(*(arrPtr+2) == *(arrPtr+4))
{
printf("Equal!");
}
else
{
printf("Not Equal");
}
return 0;
}
Question 3
#include "stdio.h"
int foo(int a)
{
printf("%d",a);
return 0;
}
int main()
{
foo;
return 0;
}
Question 4
#include "stdio.h"
typedef int (*funPtr)(int);
int inc(int a)
{
printf("Inside inc() %d\\n",a);
return (a+1);
}
int main()
{
funPtr incPtr1 = NULL, incPtr2 = NULL;
incPtr1 = &inc; /* (1) */
incPtr2 = inc; /* (2) */
(*incPtr1)(5); /* (3) */
incPtr2(5); /* (4)*/
return 0;
}
Question 5
#include "stdio.h"
int * gPtr;
int main()
{
int * lPtr = NULL;
if(gPtr == lPtr)
{
printf("Equal!");
}
else
{
printf("Not Equal");
}
return 0;
}
There are 5 questions to complete.