Home »
Aptitude Questions and Answers »
C Aptitude Questions and Answers
C Typedef - Aptitude Questions and Answers
C programming Typedef Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on typedef topics, defining/changing name of any data type, using and accessing the typedef values.
1) 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;
}
- Error
- 10,10,10,10
- 10,20,30,40
- AAA,BBB,CCC,DDD
Correct Answer - 3
10,20,30,40
2) What will be the output of following program?
#include < stdio.h >
int main()
{
typedef auto int AI;
AI var=100;
printf("var=%d",var);
return 0;
}
- var=100
- var=AI
- var=0
- Error
Correct Answer - 4
Error : more than one storage classes/ many storage classes.
Since typedef is used to define the name of data type, here auto is a storage class, can not be
type defined.
3) What will be the output of following program?
#include < stdio.h >
int main()
{
typedef char* string;
string myName="ABCDEFG";
printf("myName=%s (size=%d)",myName,sizeof(myName));
return 0;
}
- myName=ABCDEFG (size=7)
- Error
- myName=ABCDEFG (size=4)
- myName=ABCDEFG (size=8)
Correct Answer - 3
myName=ABCDEFG (size=4).
In this program char* has defined as string, statement string myName="ABCDEFG"; is char* myName="ABCDEFG" which is
a character pointer, takes 4 bytes(on 32 bit compiler) in memory.
4) What will be the output of following program?
#include < stdio.h >
int main()
{
typedef struct
{
int empid;
int bsal;
}EMP;
EMP E={10012,15100};
printf("%d,%d",E.empid,E.bsal);
return 0;
}
- 10012,15100
- 0,0
- ERROR
- 10012,10012
Correct Answer - 1
10012,15100.