C Programming :: Structures, Unions, Enums

NA
SHSTTON
8
Solv. Corr.
9
Solv. In. Corr.
17
Attempted
0 M:0 S
Avg. Time

1 / 43

What is the output of the following 'C' program ?
#include<stdio.h>
int main() {
 union {
 int a;
int b;
int c;
} u,v;
u.a = 10;
u.b = 20;
printf("%d %d \n",u.a,u.b);
return 0;
}

A20 20

B10 10

C10 20

D20 10

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
12
Solv. Corr.
6
Solv. In. Corr.
18
Attempted
0 M:0 S
Avg. Time

2 / 43

What is the output of the following 'C' problem ?
#include<stdio.h>

struct {
int x; 
int y; 
union {
int id_no;
char *name;
}b;
}s,*st;
int main()
{
st = &s;
st->x=10;
st->b.id_no = 101;
printf("%d %d\n",s.x,s.b.id_no);
return 0;
}

A10 10

B101 101

C10 101

DNoneof these

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
16
Solv. In. Corr.
16
Attempted
0 M:0 S
Avg. Time

3 / 43

What is the output of the following program ?
#include<stdio.h>
void main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s=malloc(sizeof(struct xx));
printf("%d",s->x);
printf("%s",s->name);
}

A3 hello

BGarbage value hello

C3 Garbage Value

DCompiler Error

ENone of these

 View Answer |  Discuss in Forum |  Workspace | Asked In Societe Generale |

Answer: Option D

Explanation:

Initialization should not be done for structure members inside the structure declaration

Workspace

NA
SHSTTON
0
Solv. Corr.
14
Solv. In. Corr.
14
Attempted
0 M:0 S
Avg. Time

4 / 43

What is the output of the following 'C' program ?
#include<stdio.h>
struct myStruct{
    int a;
    char b;
}*ptr;
int main(){
    struct myStruct ms={400,'A'};
    printf("%d  %d",ptr->a,ptr->b);
    return 0;
}

A400 A

B400 65

C400 97

D0 0

ECompilation error

Answer: Option D

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
3
Solv. Corr.
9
Solv. In. Corr.
12
Attempted
0 M:0 S
Avg. Time

5 / 43

What is the output of the following 'C' program ?
#include<stdio.h>
typedef struct stu1{
    char name1[6];
    char name2[6];
    double marks;
}STU1;
void main(){
    STU1 s1={"rohit","kumar",87.43},*p1;
    char *p;
    p1=&s1;
    p=memchr(p1,'u',sizeof(STU1));
    printf("%s",p); 
}

Aroh

Brohit

Cumar

Drohit kumar

ECompilation error

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
6
Solv. Corr.
6
Solv. In. Corr.
12
Attempted
0 M:0 S
Avg. Time

6 / 43

What is the output of the following 'C' program?
#include<stdio.h>
void main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s; 
printf("%d",s->x);
 printf("%s",s->name);
}

A3 hello

BGarbage Value

CCompilation error

DNone of these

Answer: Option C

Explanation:

You should not initialize variables in declaration

Workspace

NA
SHSTTON
6
Solv. Corr.
5
Solv. In. Corr.
11
Attempted
0 M:0 S
Avg. Time

7 / 43

What is the output of the following 'C' program?
#include<stdio.h>
void main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}

ANo Error

BCompiler Error

CNone of these

 View Answer |  Discuss in Forum |  Workspace | Asked In Societe Generale |

Answer: Option B

Explanation:

The structure yy is nested within structure xx.
Hence, the elements are of yy are to be accessed through the instance of structure xx, which needs an instance of yy to be known.
If the instance is created after defining the structure the compiler will not know about the instance relative to xx. Hence for nested structure yy you have to declare member.

Workspace

NA
SHSTTON
2
Solv. Corr.
10
Solv. In. Corr.
12
Attempted
0 M:0 S
Avg. Time

8 / 43

What is the output of the following 'C' program?
#include<stdio.h>
enum colors {BLACK,BLUE,GREEN,YELLOW};
int main()
{
printf("%d..%d..%d..%d",BLACK,BLUE,GREEN,YELLOW);
return 0;
}

A0..2..3..4

B0..2..2..3

C0..1..2..3

DNone of these

Answer: Option D

Explanation:

enum assigns numbers starting from 0, if not explicitly defined.

Workspace

NA
SHSTTON
2
Solv. Corr.
9
Solv. In. Corr.
11
Attempted
0 M:0 S
Avg. Time

9 / 43

What is the output of the following 'C' program?
#include<stdio.h>
enum colors {BLACK,BLUE=2,GREEN,YELLOW};
int main()
{
printf("%d..%d..%d..%d",BLACK,BLUE,GREEN,YELLOW);
return 0;
}

A0..2..3..4

B0..2..2..3

C0..1..2..3

DNone of these

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
10
Solv. Corr.
0
Solv. In. Corr.
10
Attempted
0 M:0 S
Avg. Time

10 / 43

What is the output of the following 'C' program?
#include<stdio.h>
enum colors {BLACK,BLUE=-2,GREEN,YELLOW};
int main()
{
printf("%d..%d..%d..%d",BLACK,BLUE,GREEN,YELLOW);
return 0;
}

A0..2..3..4

B0..-2..-1..0

C0..1..2..3

D0..-2..1..2

 View Answer |  Discuss in Forum |  Workspace | Asked In Societe Generale |

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace