08 UseDefineDataTypeWithAnswers
08 UseDefineDataTypeWithAnswers
1.
#include <stdio.h>
struct student
{
char *name;
};
struct student fun(void)
{
struct student *s;
s->name = "Rajesh";
return *s;
}
int main( void )
{
struct student s1 = fun();
printf("%s", s1.name);
return 0;
}
A. Rajesh
B. error
C. RajeshRajesh
D. print memory address
Answer: B
2.
#include <stdio.h>
struct test
{
int capacity;
char *course;
return 0;
}
A. KDAC Karad , D, 30, DBDA
B. DAC Karad , B, 30, BDA
C. DAC Pune , K, 120, DAC
D. KDAC , K , 120, DAC KARAD
Answer: B
3.
#include <stdio.h>
typedef struct Cell
{
int isParent;
Cell child;
}Cell;
int main(void)
{
Cell parent,child;
parent.child=child;
return 0;
}
A. successfully complied
B. successfully complied and executed
C. Compile time error
D. none of above
Answer: C
4.
#include <stdio.h>
#include <string.h>
int main(void)
{
struct Cell
{
int isParent;
char *child;
};
strcpy(c2.child,"center");
printf("\n %s",c1.child);
return 0;
}
A. Remote
B. center
C. Remotecenter
D. runtime error
Answer: D
5.
#include <stdio.h>
struct course
{
int capacity;
char coursename[10];
};
int main (void)
{
struct course arr[] = {
{220, "DAC Pune"},
{120, "KDAC Karad"},
{30, "DBDA"},
{60, "DESD"},
{120, "DMC"},
};
return 0;
}
union
6.
#include<stdio.h>
union testUnion
{
short int num;
char ch[2];
};
int main()
{
union testUnion ut;
ut.ch[0]=4;
ut.ch[1]=4;
printf("%d", ut.num);
return 0;
}
A. 4
B. 44
C. 1028
D. 516
Answer: C
7.
#include<stdio.h>
int main(void)
{
union result
{
short int persentage;
char grade[2];
};
printf("%d",r1.grade[1]);
return 0;
}
A. 0
B. 88
C. 5
D. 8
Answer: A
8.
#include<stdio.h>
union account
{
int accNumber;
static int accID;
};
int main( void )
{
union account acc1;
printf("%d", sizeof(acc1));
return 0;
}
A. 1
B. 4
C. 8
D. compile time error
Answer: D
enum
9.
#include<stdio.h>
int main( void )
{
enum color {red,green,yellow,pink,black=0};
enum color c1,c2;
c1=red;
c2=black;
printf("color code for c1=%d,c2=%d",c1,c2);
return 0;
}
A. color code for c1=0,c2=0
B. color code for c1=-4,c2=0
C. error
D. color code for c1=1,c2=0
Answer: A
10.
#include<stdio.h>
int main( void )
{
int n1=3,n2=5;
enum Code {code1=n1,code2=n2,code3=n1+n2,code4=n2-n1};
enum Code c1=code3;
printf("value=%d",c1);
return 0;
}
A. 8
B. 5
C. error
D. 0
Answer: C
11.
#include<stdio.h>
int main( void )
{
enum months {jan=1,feb,mar,apl,may,jun,jul,aug};
enum months m;
printf("size=%d",sizeof(m));
return 0;
}
A. 1
B. 4
C. 2
D. 8
E. 0
Answer: B
typedef
12.
#include<stdio.h>
typedef char *string;
int main( void )
{
string str1 = “abc”;
*string str2= “pqr”;
printf("str1=%s str2=%s",str1,str2);
return 0;
}
A. str1=abc str2=pqr
B. str1= str2=
C. error
D. prints the addresses of str1 and str2
Answer: C
13.
typedef struct time
{
int hr;
int min;
int sec;
}TIME;
int main( void )
{
struct time time = {1, 22, 33};
TIME t1 = time;
printf("%d\n", t1.hr);
return 0;
}
A. 1
B. 0
C. Compile time error
D. Run time error
Answer: A
14.
#include <stdio.h>
int modify(int num)
{
return num + 1;
}
typedef <???> funPtr;
int main(void)
{
int num;
return 0;
}
return 0;
}
16.
#include <stdio.h>
#include <string.h>
struct
{
unsigned int age : 2;
}Age;
int main(void )
{
Age.age = 3;
printf( "Age.age : %d ", Age.age );
Age.age = 4;
printf( "updated Age.age : %d\n", Age.age );
return 0;
}