C Interview Questions 121-130

This post contains 121-130 questions of c program. It will helpful to solve c aptitude questions, c quiz , c objective type questions etc in interview.

121-130 Questions

Q1:
The size of structure and union is same when they contain 
a) single member 
b) any number of members 
c) a & b 
d) none
Answer:

Q2:
The operator used to find the size of any variable 
a) sizeof 
b) Sizeof 
c) sizeOf 
d) all the above
Answer:

Q3:
The operator that is used to access the members of the structure using pointer variable 
a) . 
b) -> 
c) * 
d) none of the above
Answer:

Q4:
The operator used to access the member of the structure 
a) . 
b) -> 
c) * 
d) none of the above
Answer:

Q5:
The operator -> is same as the combination of the operators 
a) * and . 
b) & and . 
c) * and & 
d) none of the above
Answer: 

Q6:
Bitfields areused to 
a) save time 
b) save memory 
c) change order of allocation of memory 
d) none of the above
Answer:

Q7:
Union can store _________ number of values at a time 
a) all its members 
b) only 1 
b) 2 
d) cannot hold value
Answer:

Q8:
what will be the position of the file marker?
    a: fseek(ptr,0,SEEK_SET);
    b: fseek(ptr,0,SEEK_CUR);
    
Answer :
a: The SEEK_SET sets the file position marker to the starting of the file.
b: The SEEK_CUR sets the file position marker to the current position of the file.

Q9:
129.#include<stdio.h>
main()
{
    FILE *ptr;
    char i;
    ptr=fopen("zzz.c","r");
    while((i=fgetch(ptr))!=EOF)
        printf("%c",i);
}
Answer:
contents of zzz.c followed by an infinite loop

Q10:
There were 10 records stored in "somefile.dat" but the following program printed 11 names. What went wrong?
void main()
{
    struct student
    {
        char name[30], rollno[6];
    }stud;
    FILE *fp = fopen("somefile.dat","r");
    while(!feof(fp))
    {
        fread(&stud, sizeof(stud), 1 , fp);
        puts(stud.name);
    }
}
Explanation:
fread reads 10 records and prints the names successfully. It will return EOF only when fread tries to read another record and fails reading EOF (and returning EOF). So it prints the last record again. After this only the condition feof(fp) becomes false, hence comes out of the while loop.

Comments are closed.