---
title: "Syntax of struct"
subject: "Computer Programming"
chapter: 8
key: "semester_1/computer_programming:syntax-struct"
source: https://www.bctengineer.com/q/semester_1/computer_programming/syntax-struct
site: BCT Engineering
---

# Syntax of struct

Computer Programming · Chapter 8: Structures

- Asked in: 2067 Asar, 2 marks
- Video: [C_109 Structures in C - part 1| Introduction to Structures | C Programming](https://www.youtube.com/watch?v=LpHnHRI6gLc) — Jenny's Lectures CS IT
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/syntax-struct
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-8

## Question

Write the syntax used in C programming language for struct.

## Short answer

Syntax: struct tag_name { data_type member1; data_type member2; ... }; then declare variables as struct tag_name var; Example: struct student { char name[20]; int roll; }; struct student s1;

## Answer

```c
struct tag_name {
    data_type member1;
    data_type member2;
    ...
};                          /* semicolon is compulsory */

struct tag_name variable;   /* declaring a variable */
```

Example:

```c
struct student {
    char name[20];
    int roll;
};
struct student s1;
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which is the correct syntax to define a structure?
   A. struct tag_name ( data_type member1; );
   B. struct tag_name { data_type member1, }
   C. struct tag_name { data_type member1; data_type member2; };
   D. structure tag_name { member1 };
   Answer: C. Members go inside braces and the definition ends with a semicolon. (Key point: Syntax)

2. What is compulsory after the closing brace of the structure definition?
   A. A colon
   B. Nothing
   C. A period
   D. A semicolon
   Answer: D. Omitting it is a compile error. (Key point: Semicolon)

3. How is a variable of the type declared later?
   A. struct tag_name variable;
   B. tag_name struct variable;
   C. variable struct tag_name;
   D. struct variable tag_name;
   Answer: A. The keyword struct and the tag name are followed by the variable. (Key point: Declaring a variable)

## Related in Computer Programming

- [Define programming language](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adefine-programming-language) — Computer Programming, chapter 1, asked 3×
- [Syntax of while loop](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asyntax-while) — Computer Programming, chapter 5
- [Syntax of if...else](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asyntax-if-else) — Computer Programming, chapter 5
- [Syntax of static](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asyntax-static) — Computer Programming, chapter 6
- [Formatted I/O in FORTRAN with syntax](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-formatted-io-syntax) — Computer Programming, chapter 11
- [I/O functions used with data files](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-io-functions) — Computer Programming, chapter 10, asked 2×

## Related in other subjects

- [8086 assembly language operators](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3A8086-operators) — Microprocessor, chapter 3, asked 3×
- [Syntax of operator overloading](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aoperator-overloading-syntax) — Object Oriented Programming, chapter 5, asked 4×
- [Class and function template with syntax](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aclass-function-template-syntax) — Object Oriented Programming, chapter 9, asked 4×
- [Default arguments and their syntax](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Adefault-arg-define-syntax) — Object Oriented Programming, chapter 3, asked 2×
