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
  1. 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

  2. Which of the following is not a common programming language that supports structures? a. C b. Python c. Java d. Assembly Answer: d

  3. 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

  4. 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

  5. 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

  6. 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

  7. Can structures contain other structures? a. Yes b. No Answer: a

  8. 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

  9. 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

  10. 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
  1. 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.

  2. 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; };

  3. 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.

  4. 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;

  5. Can structures be passed as arguments to functions? Answer: Yes, structures can be passed as arguments to functions in programming.

  6. 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;

  7. Can a structure have a pointer as a member? Answer: Yes, a structure can have a pointer as a member in programming.

  8. 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;

  9. 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;

  10. 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.

In programming, a structure is a user-defined data type that allows the programmer to group related variables of different data types under a single name. This can make the code more organized and easier to read, as well as more efficient in terms of memory usage. In C programming, a structure is declared using the "struct" keyword followed by the name of the structure and the members enclosed in curly braces. Each member of the structure can be of a different data type, such as int, float, char, or even another structure. Structures can be useful for representing real-world objects or systems, such as a student record or a bank account. They can also be used for organizing data in databases or for passing multiple arguments to a function. Structures can be passed as arguments to functions, and they can be returned from functions as well. They can also be used in dynamic memory allocation, where memory is allocated at run time based on the size of the structure. One of the key benefits of using structures is that they can make the code more modular and easier to maintain. For example, a structure can be defined for a customer record in a banking system, and that structure can be used throughout the system, making it easier to make changes to the customer record without affecting the rest of the system. In addition to structures, C programming also includes unions, which are similar to structures but allow the programmer to define a variable that can hold different data types at different times. Overall, structures are a powerful tool in programming that allow for the creation of complex data types that can be used to represent real-world objects or systems. They can help make the code more organized, efficient, and modular, making it easier to maintain and update over time.