Structures
Union
Enums
???
100

Predict the output of the following program

#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; 

}

Compiler Error 

100

We can access the data members of a union using the _____.

'.' operator

100

 Can we create object of Enum?

No, it is not possible to create the object of Enum.

100

Which of the following operators can be applied on structure variables?

Equality comparison ( == )

Assignment ( = )

Both of the above

None of the above

Assignment ( = )


200

struct node 

  int i; 

  float j; 

}; 

struct node *s[10];

The above C declaration define 's' to be ______ (GATE CS 2000)

An array, each element of which is a pointer to a structure of type node

200

In the context of C programming, what is a union?

A data type in C programming that allows different data types to be stored in the same memory location

200

What is the similarity between a structure, union and enumeration?

A.All of them let you define new values

B.All of them let you define new data types

C.All of them let you define new pointers

D.All of them let you define new structures 

Option B

300

Predict the output of the following program

#include <stdio.h>

int main()

{

  struct site

  {

    char name[] = "PROcoder";

    int no_of_pages = 300;

  };

  struct site *ptr;

  printf("%d ", ptr->no_of_pages);

  printf("%s", ptr->name);

  getchar();

  return 0;

}

Compiler Error

300

Predict the output of the following code

#include <stdio.h>

#include <string.h>

struct Test

{

  char str[20];

};

int main()

{

  struct Test st1, st2;

  strcpy(st1.str, "PROcoder");

  st2 = st1;

  st1.str[0] = 'S';

  printf("%s", st2.str);

  return 0;

}

PROcoder

400

Assume that the size of an integer is 32 bit. What is the output of the following program?

#include<stdio.h>

struct st

{

  int x;

  static int y;

};

int main()

{

  printf("%d", sizeof(struct st));

  return 0;

}

Compiler Error

400

What does ordinal() method do in Enum?

Ordinal method returns the order in which Enum instance are declared inside Enum. For example in a DayOfWeek Enum, you can declare days in order they come e.g.

public enum WeekDay{  MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY; }

Ordinal arranges or assigns numbers to each element in Enum starting from 0. MONDAY will be 0, TUESDAY will be 1 and so on. If we call WeekDay.Thursday.ordinal() it will return 3. 

400

Consider the following C declaration 

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. The memory requirement for variable t, ignoring alignment considerations, is ________ (GATE CS 2000) 

18 bytes

500

#include <stdio.h>

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;

}

Predict the output of the above program. Assume that the size of an integer is 4 bytes and size of a character is 1 byte. Also, assume that there is no alignment needed.

Nothing is printed

500

Can Enum implement interface in Java?

Yes, Enum can implement interface in Java. Since enum is a type, similar to class and interface, it can implement interface. This gives a lot of flexibility to use Enum as specialized implementation in some cases

500

#include <stdio.h>

union test

{

  int x;

  char arr[8];

  int y;

};

int main()

{

  printf("%d", sizeof(union test));

  return 0;

}

Predict the output of the above program. Assume that the size of an integer is 4 bytes and the size of a character is 1 byte. Also, assume that there is no alignment needed.

8

M
e
n
u