Professional Documents
Culture Documents
A. String
B. Array
C. Structure
D. Files
QUESTION: Which operator is used to connect structure name to its member name?
A. dot operator(.)
B. logical operator(&&)
C. pointer operator(&)
D. Arrow operator(->)
QUESTION: Which of the following comment about the usage of structures in true?
A. Storage class can be assigned to individual member
B. The scope of the member name is confined to the particular structure, within which it is
defined
C. Individual members can be initialized within a structure type declaration
D. None of above
main()
{
struct emp
{
char name[20];
int age;
float sal;
};
struct emp e ={"Tiger"} printf("%d%d
%f",e.age,e.sal);
}
A:Garbage Collection
B:Error
C:1 0.000000
D:0 0.000000
int main()
{
union a
{
int i;
char ch[2];
};
union a u;
u.ch[0]=3;
u.ch[1]=2;
printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i);
return 0;
}
A: 3, 2, 515
B: 515, 2, 3
C: 3, 2, 5
D: 515, 515, 4
QUESTION: What will be the output of the program ?
int main()
{
union var
{
int a, b;
};
union var v;
v.a=10;
v.b=20;
printf("%d\n", v.a);
return 0;
}
A: 10
B: 20
C: 30
D: 0
int main()
{
struct value
{
int bit1:1;
int bit3:4;
int bit4:4;
}bit={1, 2, 13};
A: 1, 2, 13
B: 1, 4, 4
C:-1, 2, -3
D:-1, -2, -13
QUESTION: What will be the output of the program in 16 bit platform (Turbo C
under DOS) ?
int main()
{
struct value
{
int bit1:1;
int bit3:4;
int bit4:4;
}bit;
printf("%d\n", sizeof(bit));
return 0;
}
A: 1
B: 2
C: 4
D: 9
int main()
{
enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};
printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT);
return 0;
}
A: -1, 0, 1, 2, 3, 4
B: -1, 2, 6, 3, 4, 5
C: -1, 0, 6, 2, 3, 4
D: -1, 0, 6, 7, 8, 9
int main()
{
enum status {pass, fail, absent};
enum status stud1, stud2, stud3;
stud1 = pass;
stud2 = absent;
stud3 = fail;
printf("%d %d %d\n", stud1, stud2, stud3);
return 0;
}
A: 0, 1, 2
B: 1, 2, 3
C: 0, 2, 1
D: 1, 3, 2
QUESTION: What will be the output of the program in Turbo C (under DOS)?
int main()
{
struct emp
{
char *n;
int age;
};
struct emp e1 = {"Dravid",
23}; struct emp e2 = e1;
strupr(e2.n);
printf("%s\n", e1.n);
return 0;
}
A: Error: Invalid structure assignment
B: DRAVID
C: Dravid
D: No output
QUESTION: What will be the output of the program in 16-bit platform (under DOS)?
int main()
{
struct node
{
int data;
struct node *link;
};
struct node *p, *q;
p = (struct node *) malloc(sizeof(struct
node)); q = (struct node *)
malloc(sizeof(struct node)); printf("%d,
%d\n", sizeof(p), sizeof(q));
return 0;
}
A: 2, 2
B: 8, 8
C: 5, 5
D: 4, 4
int main()
{
struct byte
{
int one:1;
};
struct byte var = {1};
printf("%d\n", var.one);
return 0;
}
A: 1
B:-1
C: 0
D: Error
QUESTION: Which of the following statements correct about the below program?
int main()
{
struct emp
{
char name[25];
int age;
float sal;
};
struct emp e[2];
int i=0;
for(i=0; i<2; i++)
scanf("%s %d %f", e[i].name, &e[i].age, &e[i].sal);
QUESTION: Which of the following statements correct about the below program?
int main()
{
union a
{
int i;
char ch[2];
};
union a u1 = {512};
union a u2 = {0, 2};
return 0;
}
A: 1, 2
B: 2,3
C: 1,2,3
D: 1,3,4
QUESTION: Which of the following statements correct about the below code?
maruti.engine.bolts=25;
QUESTION: The '.' operator can be used access structure elements using a structure
variable
A: True
B: False
QUESTION: The elements of union are always accessed using & operator
A: Yes
B: No
typedef struct s
{
int a;
float b;
}s;
A: YeS
B: No
QUESTION: If a char is 1 byte wide, an integer is 2 bytes wide and a long integer is 4
bytes wide then will the following structure always occupy 7 bytes?
struct ex
{
char ch;
int i;
long int a;
};
A: Yes
B: No
QUESTION: Which of the following are themselves a collection of different data types?
A: String
B: Structure
C: Char
D: All of the mentioned
QUESTION: Which operator connects the structure name to its member name
A: -
B: .
C: Both (b) and (c)
D: None of the above
A :Nothing
B: Compile time error
C: Junk
D: 8
Struct test
{
int k;
char c;
};
Union temp
{ int a;
float b;
char c;
};
union temp s={1,2.5,'A'}//REF LINE
A: A
B: B
C: C
D: Such declaration are illegal
union uTemp
{double a;
int b[10];
char c;
} u;
QUESTION: The correct syntax to access the member of the ith structure in the array
Of structures is?
Assuming:
struct temp
{
int b;
}s[50];
A: s.b.[i];
B: s.[i].b;
C: s.b[i];
D: s[i].b;
QUESTION: Which of the following are themselves a collection of different data types?
A: structures
B: string
C: char
D: All of the mentioned
#include <stdio.h>
struct temp
{
int a;
int b;
int c;
};
main()
{
struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} }
struct temp
{
int a;
int b;
int c;
} p[] = {0};
main()
{ printf("%d", sizeof(p));
}
A: 4
B: 12
C: 16
D: Can‟t be estimated due to ambigous initialization of array
struct student
{
};
void main()
{
struct student s[2];
printf("%d", sizeof(s));
}
A: 2
B: 4
C: 8
D: 0
struct
{
int k;
char c;
};
int main()
{
struct p;
p.k = 10;
printf("%d\n", p.k);
}
#include <stdio.h>
struct
{
int k;
char c;
} p;
int p = 10;
int main()
{
p.k = 10;
printf("%d %d\n", p.k, p);
}
#include <stdio.h>
struct p
{
int k;
char c;
};
int p = 10;
int main()
{
struct p x;
x.k = 10;
printf("%d %d\n", x.k, p);
}
#include <stdio.h>
struct p
{
int k;
char c;
float f;
};
int p = 10;
int main()
{
struct p x = {1, 97};
printf("%f %d\n", x.f, p);
}
#include <stdio.h>
struct p
{
int k;
char c;
float f;
};
int main()
{
struct p x = {.c = 97, .f = 3, .k = 1};
printf("%f\n", x.f);
}
A: 3.000000
B: Compile time error
C: Undefined behavior
D: 1.000000
#include <stdio.h>
struct p
{
int k;
char c;
float f;
};
int main()
{
struct p x = {.c = 97, .k = 1, 3};
printf("%f \n", x.f);
}
A: 3.000000
B: 0.000000
C: Compile time error
D: Undefined behaviour
#include <stdio.h>
struct p
{
int k;
char c;
float f;
};
int main()
{
struct p x = {.c = 97};
printf("%f\n", x.f);
}
A: 0.000000
B: Somegarbagevalue
C: Compile time error
D: None of the mentioned
struct x x
{
int a;
long b;
} s;
union y y
{
int a;
long b;
} u;
print sizeof( s ) and sizeof( u ) if sizeof( int ) = 4 and sizeof( long ) = 4
A:sizeof( s ) = 8, sizeof( u ) = 4
B:sizeof( s ) = 4, sizeof( u ) = 4
C:sizeof( s ) = 4, sizeof( u ) = 8
D:sizeof( s ) = 8, sizeof( u ) = 8
#include <stdio.h>
main()
{
struct s1 { int i ;};
struct s2 { int i ;};
struct s1 st1;
struct s2 st2;
st1.i = 5;
st2 = st1;
printf(“ %d”, st2.i);
}
A:5
B:1004
C:Syntax error
D:None
union x
{ char ch;
int I;
double j;
} u_var;
A:16 byte
B:13 byte
C:8 byte
D:4 byte
typedef struct p
{
int x, y;
}k;
int main()
{
struct p p = {1, 2};
k k1 = p;
printf("%d\n", k1.x);
}
#include <stdio.h>
struct sample
{
int a=0;
char b='A';
float c=10.5;
};
int main()
{
struct sample s; printf("%d,%c,
%f",s.a,s.b,s.c); return 0;
}
A: Error
B: 0,A,10.5
C: 0,A,10.500000
D: No Error , No Output
#include <stdio.h>
struct sample
{
int a;
}sample;
int main()
{
sample.a=100;
printf("%d",sample.a);
return 0;
}
A:0
B:100
C:ERROR
D:Warning
QUESTION: What will be the output of following program ? (On 16 bit compiler)
#include <stdio.h>
int main()
{
union values
{
int intVal;
char chrVal[2];i
};
printf("\n%c,%c,%d",val.chrVal[0],val.chrVal[1],val.intVal);
return 0;
}
A: A,B,0
B: A,B,16961
C: B,B,66
D: A,A,65
QUESTION: What will be the output of following program ? (On 16 bit compiler)
#include <stdio.h>
int main()
{
union values
{
unsigned char a;
unsigned char b;
unsigned int c;
};
union values val;
val.a=1;
val.b=2;
val.c=300;
printf("%d,%d,%d",val.a,val.b,val.c);
return 0;
}
A: 44,44,300
B: 1,2,300
C: 2,2,300
D: 256,256,300
QUESTION: What will be the output of following program ? (On 16 bit compiler)
#include <stdio.h>
int main()
{
typedef struct
tag{ char str[10];
int a;
}har;
har h1,h2={"IHelp",10};
h1=h2;
h1.str[1]='h'; printf("%s,
%d",h1.str,h1.a); return 0;
}
A:ERROR
B:IHelp,10
C:IHelp,0
D:Ihelp,10
QUESTION: What will be the output of following program ?
#include <stdio.h>
int main()
{
struct std
{
char name[30];
int age;
};
struct std s1={"Mike",26};
struct std s2=s1;
#include <stdio.h>
int main()
{
union test
{
int i;
int j;
};
union test var=10; printf("%d,
%d\n",var.i,var.j);
}
A:10,10
B:10,0
C:0,10
D:Error
A:b->var
B:b.var
C:b-var
D:b>var
QUESTION: A short integer occupies 2 bytes an, ordinary integer 4 bytes and a long
integer occupies 8 bytes of memory
If a structure is defined as
struct TAB{
short a;
int b;
long c;
}TABLE[10];
union id{
char color[12];
int size;}
shirt,Jeans;
denotes shirt and Jeans are variable of type id and
union test
{
int x;
char arr[4];
int y;
};
int main()
{
union test t;
t.x = 0;
t.arr[1] = 'G';
printf("%s", t.arr);
return 0;
}
A:Nothing is printed
B:G
C:Garbage character followed by „G‟
D:Garbage character followed by „G‟, followed by more garbage
characters
QUESTION:
#include<stdio.h>
struct st
{
int x;
struct st next;
};
int main()
{
struct st temp;
temp.x = 10;
temp.next = temp;
printf("%d", temp.next.x);
return 0;
}
struct {
short s[5];
union {
float y;
long z;
}u;
} t;
Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes,
respectively. How much memory requirement for variable t?
A:22 bytes
B:14 bytes
C:18 bytes
D:10 bytes
QUESTION:
#include<stdio.h>
struct st
{
int x;
static int y;
};
int main()
{
printf("%d", sizeof(struct st));
return 0;
}
A:4
B:8
C:Compile Error
D:Runtime Error
QUESTION:
union test
{
int x;
char arr[8];
int y;
};
int main()
{
printf("%d", sizeof(union test));
return 0;
}
What is the output of above program. Assume that the size of an integer is 4 bytes and
size of character is 1 byte
A:12
B:16
C:8
D:Compile time error
QUESTION:
# include <iostream>
# include <string.h>
using namespace std;
struct Test
{
char str[20];
};
int main()
{
struct Test st1, st2;
strcpy(st1.str, "GeeksQuiz");
st2 = st1;
st1.str[0] = 'S';
cout << st2.str;
return 0;
}
A:Segmentation Fault
B:SeeksQuiz
C:GeeksQuiz
D:Compiler Error
int main()
{
struct Point p1 = {.y = 0, .z = 1, .x = 2};
printf("%d %d %d", p1.x, p1.y, p1.z);
return 0;
}
A:Compiler Error
B:2 0 1
C:0 1 2
D:2 1 0
Student s1;
struct Student s2;
A:True
B:False
#include "stdio.h"
int main()
{
struct {int a[2];} arr[] = {{1},{2}};
printf("%d %d %d %d",arr[0].a[0],arr[0].a[1],arr[1].a[0],arr[1].a[1]);
return 0;
}
A:Compile error because arr has been defined using struct type incorrectly. First struct type
should be defined using tag and then arr should be defined using that tag.
B:Compile error because apart from definition of arr, another issue is in the initialization of
array of struct i.e. arr[].
C:No compile error and it‟ll print 1 0 2 0
D:No compile error and it‟ll print 1 2 0 0
#include "stdio.h"
int main()
{
struct {int i; char c;} myVar = {.c ='A',.i = 100};
printf("%d %c",myVar.i, myVar.c);
return 0;
}
A:Compile error because struct type (containing two fields of dissimilar type i.e. an int and a
char) has been mentioned along with definition of myVar of that struct type.
B:Compile error because of incorrect syntax of initialization of myVar. Basically, member of
operator (i.e. dot .) has been used without myVar.
C:Compile error for not only B but for incorrect order of fields in myVar i.e. field c has been
initialized first and then field i has been initialized.
D:No compile error and it‟ll print 100 A.
#include "stdio.h"
int main()
{
union {int i1; int i2;} myVar = {.i2 =100};
printf("%d %d",myVar.i1, myVar.i2);
return 0;
}