20 Lecture
CS201
Midterm & Final Term Short Notes
Structures
Structures are a collection of related variables grouped together under a single name, allowing for more efficient and organized storage of data. They are a fundamental concept in programming, allowing for the creation of complex data types that
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is a structure in programming? a. A way to control program flow b. A collection of related variables c. A type of loop d. A type of function Answer: b
Which of the following is not a common programming language that supports structures? a. C b. Python c. Java d. Assembly Answer: d
In C programming, how are the members of a structure accessed? a. By using a dot (.) operator b. By using a colon (:) operator c. By using a semicolon (;) operator d. By using a comma (,) operator Answer: a
What is the purpose of a structure? a. To create a function b. To control program flow c. To group related variables d. To write comments Answer: c
Which of the following is not a data type that can be a member of a structure? a. Integer b. Float c. String d. Function Answer: d
Which of the following is a valid way to declare a structure in C? a. struct myStructure {} b. myStructure {} c. myStructure type {} d. struct type myStructure {} Answer: d
Can structures contain other structures? a. Yes b. No Answer: a
What is the difference between a structure and an array? a. Structures are used for numeric data while arrays are used for text data b. Structures can hold different data types while arrays can only hold one data type c. Structures and arrays are the same thing d. Arrays can only hold a fixed number of elements while structures can hold as many as needed Answer: b
Which of the following is not a common use for structures in programming? a. Representing real-world objects b. Grouping related variables c. Organizing program flow d. Storing data in databases Answer: c
What is the keyword used to declare a structure in Java? a. struct b. class c. object d. instance Answer: b
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is a structure in programming? Answer: A structure is a user-defined data type that allows a programmer to group together related variables of different data types under a single name.
How do you declare a structure in C programming? Answer: A structure is declared using the keyword "struct" followed by the name of the structure and the members enclosed in curly braces. For example: struct student { char name[20]; int age; float marks; };
What is the difference between a structure and a union? Answer: A structure is a user-defined data type that allows a programmer to group related variables of different data types, while a union is a user-defined data type that allows a programmer to define a variable that can hold different data types at different times.
How are the members of a structure accessed in C programming? Answer: The members of a structure are accessed using the dot (.) operator. For example: struct student s; s.age = 20;
Can structures be passed as arguments to functions? Answer: Yes, structures can be passed as arguments to functions in programming.
How can you assign values to the members of a structure in C programming? Answer: The members of a structure can be assigned values using the dot (.) operator. For example: struct student s; s.age = 20; s.marks = 85.5;
Can a structure have a pointer as a member? Answer: Yes, a structure can have a pointer as a member in programming.
What is the purpose of typedef in C programming with regards to structures? Answer: The purpose of typedef in C programming is to create an alias or alternate name for a structure, making it easier to use in code. For example: typedef struct { char name[20]; int age; float marks; } student;
How can you access the members of a structure using a pointer? Answer: The members of a structure can be accessed using a pointer using the arrow (->) operator. For example: struct student *ptr; ptr->age = 20;
What is the difference between a structure and an array of structures? Answer: An array of structures is a collection of structures of the same type stored in contiguous memory locations, while a structure is a single instance of a user-defined data type.