Predict the output of above program. Assume that the size of an integer is 4 bytes and size of character is 1 byte. Also assume that there is no alignment needed.
union test
{
int x;
char arr[4];
int y;
};
int main()
{
union test t;
t.x = 0;
t.arr[1] = 'G';
printf("%s", t.arr);
return 0;
}
Answer: A
No answer description available for this question.
Enter details here
Which of the following cannot be a structure member?
Answer: B
No answer description available for this question.
Enter details here
What is the output of this program?
#include
struct test {
int x = 0;
char y = 'A';
};
int main()
{
struct test t;
printf("%d, %c", s.x, s.y);
return 0;
}
Answer: B
No answer description available for this question
Enter details here
Enumeration (or enum) is a ______ data type in C?
Answer: A
Enumeration (or enum) is a user defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.
Enter details here
Which of the following share a similarity in syntax? 1. Union 2. Structure 3. Arrays 4. Pointers
Answer: B
No answer description available for this question
Enter details here
What will be the output of the following C code?
#include
enum hi{a,b,c};
enum hello{c,d,e};
main()
{
enum hi h;
h=b;
printf("%d",h);
return 0;
}
Answer: C
The code shown above results in an error: re-declaration of enumerator ‘c’. All enumerator constants should be unique in their scope.
Enter details here
Pick the best statement for the below program:
#include "stdio.h"
int main()
{
union {int i1; int i2;} myVar = {.i2 =100};
printf("%d %d",myVar.i1, myVar.i2);
return 0;
}
Answer: C
No answer description available for this question.
Enter details here
For the following function call which option is not possible? func(&s.a); //where s is a variable of type struct and a is the member of the struct.
Answer: A
No answer description available for this question
Enter details here
Union differs from structure in the following way
Answer: B
When a variable is associated with a structure, the compiler allocates the memory for each member. The size of structure is greater than or equal to the sum of sizes of its members. The smaller members may end with unused slack bytes. While in case of Union when a variable is associated with a union, the compiler allocates the memory by considering the size of the largest memory. So, size of union is equal to the size of largest member.
Enter details here
#include
typedef enum{
Male=-1, Female
}SEX;
int main()
{
SEX var = Male;
SEX var1 = Female;
printf("%d %d",var, var1);
return 0;
}
Answer: A
No answer description available for this que
Enter details here