C Interview Questions 111-120

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

111-120 Questions

Q1:
enum colors {BLACK,BLUE,GREEN}
main()
{
    printf("%d..%d..%d",BLACK,BLUE,GREEN);
    return(1);
}
Answer:
0..1..2

Q2:
#include<stdio.h>
main()
{
    struct xx
    {
        int x=3;
        char name[]="hello";
    };
    struct xx *s=malloc(sizeof(struct xx));
    printf("%d",s->x);
    printf("%s",s->name);
}
Answer:
Compiler Error

Q3:
struct aaa{
    struct aaa *prev;
    int i;
    struct aaa *next;
};
main()
{
    struct aaa abc,def,ghi,jkl;
    int x=100;
    abc.i=0;abc.prev=&jkl;
    abc.next=&def;
    def.i=1;def.prev=&abc;def.next=&ghi;
    ghi.i=2;ghi.prev=&def;
    ghi.next=&jkl;
    jkl.i=3;jkl.prev=&ghi;jkl.next=&abc;
    x=abc.next->next->prev->next->i;
    printf("%d",x);
}
Answer:
2

Q4:
struct point
{
    int x;
    int y;
};
struct point origin,*pp;
main()
{
    pp=&origin;
    printf("origin is(%d%d)\n",(*pp).x,(*pp).y);
    printf("origin is (%d%d)\n",pp->x,pp->y);
}
Answer:
origin is(0,0)
origin is(0,0)

Q5:
What is the output for the program given below 
typedef enum errorType{warning, error, exception,}error;
main()
{
    error g1;
    g1=1;
    printf("%d",g1);
}
Answer:
Compiler error: Multiple declaration for error  

Q6:
typedef struct error
{
    int warning, error, exception;
}error;
main()
{
    error g1;
    g1.error =1;
    printf("%d",g1.error);
}
Answer:
1

Q7:
main()
{
    struct student
    {
        char name[30];
        struct date dob;
    }stud;
    struct date
    {
        int day,month,year;
    };
    scanf("%s%d%d%d",stud.rollno,&student.dob.day,
                        &student.dob.month, &student.dob.year);
}
Answer:
Compiler Error: Undefined structure date

Q8:
Is the following code legal?
struct a
{
    int x;
    struct a *b;
}
Answer:
Yes.

Q9:
#include<stdio.h>
main()
{
    struct xx
    {
        int x;
        struct yy
        {
            char s;
            struct xx *p;
        };
        struct yy *q;
    };
}
Answer:
Compiler Error

Q10:
Structures may contains 
a) multiple data items 
b) single data items 
c) a only 
d) a&b
Answer:

Comments are closed.