Total Pageviews

Tuesday, 10 June 2014

C interview Questions



  • What will print out?
    main()

            char
     *p1=“name”
            char
     *p2;
            p2=(char*)malloc(20);
            memset (p2, 0, 20);
            while(*p2++ = *p1++); 
            printf
    (“%sn”,p2);
    }
    Answer:empty string.
  • What will be printed as the result of the operation below:
    main()

        int
     x=20,y=35;
        x=y++ + x++;
        y= ++y + ++x; 
        printf
    (“%d%dn”,x,y);
    }
    Answer : 5794
  • What will be printed as the result of the operation below:
    main()
    {
        int x=5;
        printf(“%d,%d,%dn”,x,x< <2,x>>2);
    }
    Answer: 5,20,1
  • What will be printed as the result of the operation below:
    #define swap(a,b) a=a+b;b=a-b;a=a-b;
    void main()
    {
        int x=5, y=10;
        swap (x,y);
        printf(“%d %dn”,x,y);
        swap2(x,y);
        printf(“%d %dn”,x,y);
    }
    int swap2(int a, int b)
    {
        int temp;
        temp=a;
        b=a;
        a=temp;
        return 0;
    }
    Answer: 10, 5
    10, 5
  • No comments:

    Post a Comment