Section A — 1 Mark Questions
1. What is a pointer in C? [1 Mark]
Answer: A pointer is a variable that stores the memory address of another variable.
2. Which operator is used to get the address of a variable? [1 Mark]
Answer: The address-of operator, represented by &.
3. What is the dereferencing operator in C? [1 Mark]
Answer: The asterisk symbol (*), used to access the value at a specific address.
4. What is function prototyping? [1 Mark]
Answer: A declaration of a function that tells the compiler about the function name, return type, and parameters before its actual definition.
5. What keyword is used to define a structure in C? [1 Mark]
Answer: The struct keyword.
6. Can a structure contain elements of different data types? [1 Mark]
Answer: Yes, a structure is a collection of variables of possibly different types.
7. What is the purpose of the dot (.) operator in structures? [1 Mark]
Answer: It is used to access members of a structure variable.
8. What is the entry point of a C program? [1 Mark]
Answer: The main function.
9. How do you declare a pointer to an integer? [1 Mark]
Answer: int *ptr;
10. What is the size of a pointer variable? [1 Mark]
Answer: It depends on the architecture, but it typically holds the size of a memory address (e.g., 8 bytes on a 64-bit system).
11. Can structures be nested? [1 Mark]
Answer: Yes, a structure can contain another structure as a member.
12. What does the NULL pointer signify? [1 Mark]
Answer: It signifies that a pointer is not pointing to any valid memory location.
13. Which operator is used to access structure members via a pointer? [1 Mark]
Answer: The arrow operator (->).
14. Are structure members stored in contiguous memory locations? [1 Mark]
Answer: Yes, they are stored in contiguous memory.
15. What happens if you do not provide a return type for the main function? [1 Mark]
Answer: In modern C, it defaults to int, though explicitly specifying it is standard practice.
16. What is a dangling pointer? [1 Mark]
Answer: A pointer that points to a memory location that has been deallocated or freed.
17. How is an array of structures declared? [1 Mark]
Answer: struct TagName arrayName[size];
18. What is the advantage of using pointers? [1 Mark]
Answer: They allow dynamic memory management and efficient array/structure access.
19. Can a function return a structure? [1 Mark]
Answer: Yes, a function can return a structure by value.
20. What is the limitation of comparing two structures using ==? [1 Mark]
Answer: C does not support direct comparison of structure variables using ==.
Section B — 2/3 Mark Questions
1. Differentiate between the dot (.) and arrow (->) operators. [2 Marks]
Answer: The dot operator is used to access members of a structure variable directly. The arrow operator is used to access members of a structure when working with a pointer to that structure.
2. Explain the role of function prototyping with an example. [3 Marks]
Answer: Prototyping allows the compiler to perform type-checking before the function is called. Example: int add(int a, int b); declares the function signature so that calls to it are validated for the correct number and type of arguments.
3. Why are structures considered user-defined data types? [2 Marks]
Answer: Because they allow programmers to combine different primitive data types (int, float, char) into a single name, effectively creating a custom data structure tailored to specific problem domains.
4. What is the importance of the main function in C? [2 Marks]
Answer: The main function is the mandatory starting point of execution for any C program. The operating system calls this function to initiate the program logic.
5. How do you declare and initialize a structure? [3 Marks]
Answer: Define the structure using struct tag { member_list }; then create an instance like struct tag varName = {value1, value2};. This initializes the members in the order they were defined.
6. Explain the concept of pointer arithmetic. [3 Marks]
Answer: Pointer arithmetic involves incrementing or decrementing a pointer. When you add 1 to a pointer, it points to the next memory address based on the size of the data type it points to (e.g., an integer pointer moves by 4 bytes).
7. Mention two limitations of C structures. [2 Marks]
Answer: First, you cannot compare structure variables directly using the == operator. Second, structures do not support built-in methods or functions inside the definition like classes in C++.
8. What is an array of structures? [2 Marks]
Answer: It is a collection of structures of the same type stored in contiguous memory, allowing for the management of multiple related records, such as storing student details for a whole class.
9. How are pointers used to pass arguments to functions? [3 Marks]
Answer: By passing a variable's address (call-by-reference), the function gains access to the original variable's memory. This allows the function to modify the actual variable's value, which persists after the function returns.
10. Explain the need for structures in C. [2 Marks]
Answer: Structures are needed to represent complex data objects that require multiple variables of different types, such as a Date consisting of day, month, and year.
Section C — 5 Mark Questions
1. Explain the concept of Pointers in C, including their declaration, initialization, and dereferencing with an example. [5 Marks]
Answer: Pointers are powerful variables that hold memory addresses rather than direct values.
Declaration
A pointer is declared using the asterisk (*) syntax: int *ptr;.Initialization
A pointer is initialized by assigning the address of a variable to it using the & operator: int x = 10; ptr = &x;.Dereferencing
To access the value stored at the memory address held by the pointer, we use the * operator again: int val = *ptr;. This fetches the value 10 from the address stored in ptr. Pointers are essential for dynamic memory allocation and passing large data structures to functions efficiently.2. Describe the syntax and usage of Structures in C. Provide a clear example of how to define and use them. [5 Marks]
Answer: Structures allow the grouping of heterogeneous variables under one name.
Syntax
struct Student { int id; float marks; };.Usage
To use a structure, you create a variable of that type: struct Student s1;.Accessing Members
You access members using the dot operator: s1.id = 101;. Structures are crucial for modeling real-world data like employee records, books in a library, or geometric points. By grouping related data, code becomes more readable, maintainable, and logically organized.3. Compare call-by-value and call-by-reference using pointers in C. [5 Marks]
Answer: In C, how we pass arguments significantly impacts memory usage and data modification.
Call-by-Value
A copy of the actual parameter is passed to the function. Changes made inside the function do not affect the original variable. It is safer but requires more memory for large objects.Call-by-Reference
The address of the variable is passed using a pointer. The function can access the original memory location, meaning any changes made inside the function are reflected in the original variable. This is highly efficient for passing large structures, as only the memory address is copied, not the entire data set.4. Explain the limitations of structures in C and how they are addressed. [5 Marks]
Answer: While structures are robust, they have inherent limitations.
Limited Built-in Operations
C structures do not support built-in operators for comparison (==) or assignment (=). Assignment works by copying members, but comparison must be done member-by-member.Lack of Encapsulation
All members are public by default, and there is no concept of data hiding or methods attached to the structure.Workarounds
To overcome these, developers often write custom functions to compare structures or manage complex initialization. While these limitations distinguish C from object-oriented languages like C++, C structures remain the backbone of efficient data organization in systems programming.5. Discuss the importance of the main function and function prototyping in C program structure. [5 Marks]
Answer: A well-structured C program relies on the proper use of the main function and prototypes.