Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of following program ?

#include <stdio.h>
int main()
{
    typedef int AAA,BBB,CCC,DDD;
    AAA aaa=10;
    BBB bbb=20;
    CCC ccc=30;
    DDD ddd=40;
    printf("%d,%d,%d,%d",aaa,bbb,ccc,ddd);
    return 0;
}

 

  • A.Error
  • B.10,10,10,10
  • C.10,20,30,40
  • D.AAA,BBB,CCC,DDD

Answer: C

Correct answer: 10,20,30,40

A single typedef can declare several names, so AAA, BBB, CCC and DDD all become aliases for int. They are four names for one type, not four distinct types, so the four variables are ordinary independent ints holding 10, 20, 30 and 40. Sharing an alias creates no relationship between the variables at all.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.