Computer ScienceNEB 2081 (MCQs)

What is the correct syntax to declare a structure in C ? a) struct b) define struct

1

Answer

The correct syntax to declare a structure in C is:

struct structure_name {
    data_type member1;
    data_type member2;
    // ...
};

Explanation:

  • A structure in C is declared using the struct keyword followed by a name (e.g., structure_name).
  • The structure body is enclosed in curly braces {} and contains member variables (data types and names).
  • A semicolon (;) is required at the end of the declaration.

Incorrect options:

  • a) struct { } → Missing structure name and member variables.
  • b) define struct → Incorrect syntax; define is used for macros, not structures.

Example:

struct Student {
    char name[50];
    int roll_no;
    float marks;
};

This declares a structure named Student with three members: name, roll_no, and marks.

Discussion

Loading…

More Computer Science questions

All Computer Science old questions