1. What is the standard identifier for the first element in an array?
Answer:
Explanation:
In C programming, array indices start at 0. Therefore, the first element of an array is accessed using index 0.
2. Which of the following is a logical operator in C?
Answer:
Explanation:
The '&&' operator is a logical AND operator in C. It is used to combine two conditions.
3. What does the printf function do?
Answer:
Explanation:
The printf function in C is used to write output to the standard output, typically the screen.
4. How do you declare a pointer in C?
Answer:
Explanation:
In C, a pointer is declared using an asterisk (*) before the pointer name. For example, int *p; declares a pointer to an integer.
5. Which header file is required for using the malloc and free functions?
Answer:
Explanation:
The malloc and free functions are part of the standard library, so the <stdlib.h> header file is required to use these functions.
6. What is the purpose of the return 0; statement in a C program?
Answer:
Explanation:
The return 0; statement in the main function of a C program indicates successful program termination and returns control to the operating system.
7. What does the 'sizeof' operator in C return?
Answer:
Explanation:
The sizeof operator in C is used to determine the size (in bytes) of a data type or a variable.
8. Which of the following is the correct way to declare a multi-dimensional array in C?
Answer:
Explanation:
In C, a multi-dimensional array is declared using rows and columns like int arr[3][4];, representing a 3×4 array.
9. What is a segmentation fault in C?
Answer:
Explanation:
A segmentation fault occurs when a program attempts to access a region of memory that it is not allowed to access, or attempts to access memory in a way that is not allowed.
10. Which of the following is true about the const keyword in C?
Answer:
Explanation:
The const keyword in C is used to declare constants and make variables unmodifiable. Once a const variable is assigned a value, it cannot be altered by the program.
11. Which of the following correctly declares a function in C?
Answer:
Explanation:
In C, a function is declared with the return type first (int), followed by the function name and parameters in parentheses.
12. In C, which library function is used to compare two strings?
Answer:
Explanation:
The strcmp() function from the string.h library is used in C to compare two strings.
13. In C, which function is used to allocate memory without initializing it?
Answer:
Explanation:
The malloc() function is used to allocate a specified amount of memory without initializing it. Unlike calloc(), which initializes the allocated memory.
14. Which of the following is true about a static variable in C?
Answer:
Explanation:
Static variables in C retain their value between function calls and are not reinitialized each time the function is called.
15. What is the purpose of the #include preprocessor directive in C?
Answer:
Explanation:
The #include directive is used to include the contents of a specified file into the current source file.
16. What is the purpose of the continue statement in a loop in C?
Answer:
Explanation:
The continue statement in C skips the remaining code inside the loop for the current iteration and jumps to the next iteration of the loop.
17. What is the effect of the #define directive in C?
Answer:
Explanation:
The #define directive in C is used to define a macro, which is a fragment of code that is given a name. Whenever the macro name is encountered by the compiler, it is replaced by the contents of the macro.
18. Which of the following operators checks if two values are not equal in C?
Answer:
Explanation:
The != operator in C is used to check if two values are not equal.
19. How are command-line arguments passed to a main() function in C?
Answer:
Explanation:
Command-line arguments are passed to a main() function in C using int main(int argc, char *argv[]). Here argc represents the number of arguments, and argv[] is an array of pointers to the arguments.
20. Which data type is suitable for storing a large text such as a book in C?
Answer:
Explanation:
A char array is suitable for storing large texts such as books in C, as it can hold multiple characters, including special characters and spaces.
21. What is the return type of the calloc() function in C?
Answer:
Explanation:
The calloc() function in C returns a void pointer. It allocates memory and initializes all bits to zero.
22. What does the NULL macro represent in C?
Answer:
Explanation:
In C, NULL is a macro representing a zero value pointer, used in pointer initialization and comparisons.
23. Which of the following is not a storage class specifier in C?
Answer:
Explanation:
volatile is a type qualifier in C, not a storage class specifier. The storage class specifiers are static, register, extern, and auto.
24. What is the purpose of a function prototype in C?
Answer:
Explanation:
A function prototype in C is a declaration of a function that specifies the function's name, return type, and parameters without the body.
25. Which keyword is used to prevent any changes in the variable within a C program?
Answer:
Explanation:
The const keyword is used in C to declare a constant value that cannot be modified after it is set.
26. What is the purpose of the lvalue and rvalue in C?
Answer:
Explanation:
In C, an lvalue (left value) refers to an expression that points to a memory location, whereas an rvalue (right value) is the value stored at that location.
27. What does the auto keyword do in C?
Answer:
Explanation:
The auto keyword in C specifies automatic storage duration for a variable, which is the default for local variables.
28. What is the effect of the break statement inside a switch statement in C?
Answer:
Explanation:
The break statement in a switch case in C causes the control to exit from the switch statement, preventing fall-through to subsequent cases.
29. How can you pass an array to a function in C?
Answer:
Explanation:
In C, an array can be passed to a function by passing the array name, which is a pointer to the first element of the array.
30. What is a macro in C programming?
Answer:
Explanation:
In C, a macro is a preprocessor directive that defines a name for a block of code or a value, allowing code substitution before the program is compiled.
31. What does the exit(0) function do in a C program?
Answer:
Explanation:
The exit(0) function in C is used to terminate a program execution successfully. An exit code of 0 typically indicates successful completion.
32. What is a pointer in C programming?
Answer:
Explanation:
A pointer in C is a variable that stores the memory address of another variable. Pointers are used for various purposes, including dynamic memory allocation, arrays, functions, and data structures.
33. What is the purpose of the & operator in C?
Answer:
Explanation:
The & operator in C serves two purposes: when used with a variable, it gives the address of the variable (address-of operator), and when used between two numbers, it performs a bitwise AND operation.
34. In C, what is a header file?
Answer:
Explanation:
In C, a header file contains preprocessor directives, function prototypes, and definitions of types and macros, which are included in a C program using the #include directive.
35. What is the purpose of the do…while loop in C?
Answer:
Explanation:
The do…while loop in C executes its block of code at least once and then continues to execute it as long as the specified condition is true.
36. What does a static variable within a function do?
Answer:
Explanation:
A static variable within a function retains its value between successive calls to that function, maintaining its previous value across various calls.
37. What is the correct syntax to return a pointer from a function in C?
Answer:
Explanation:
In C, to return a pointer from a function, the return type should be a pointer type. For example, int* function(); declares a function returning a pointer to an int.
38. Which of the following is true about the const qualifier in C?
Answer:
Explanation:
The const qualifier in C is used to declare a constant that cannot be modified after its initialization.
39. How is dynamic memory allocation done in C?
Answer:
Explanation:
Dynamic memory allocation in C is done using functions like malloc() to allocate memory and free() to deallocate memory.
40. In C, which header file is necessary for using the printf and scanf functions?
Answer:
Explanation:
The printf and scanf functions are part of the standard input/output library in C, and they require the inclusion of the <stdio.h> header file.
41. What does the goto statement do in C?
Answer:
Explanation:
The goto statement in C allows the program to jump to a specified label. It is generally advised to use goto sparingly as it can make the program flow difficult to follow.
42. Which of the following correctly declares an array of pointers in C?
Answer:
Explanation:
int *ptr[10]; declares an array of 10 integer pointers in C.
43. What is the purpose of the strncpy function in C?
Answer:
Explanation:
The strncpy function copies a specified number of characters from one string to another, ensuring that the destination string does not get overflowed.
44. What is the default return type of a function in C if it is not specified?
Answer:
Explanation:
In C, if the return type of a function is not explicitly specified, it defaults to returning an integer (int).
45. What is a union in C?
Answer:
Explanation:
A union in C is a user-defined data type where all members share the same memory location. A union can store different data types, but only one at a time.
46. What is a void pointer in C?
Answer:
Explanation:
A void pointer, also known as a generic pointer, is a special type of pointer that can be pointed at objects of any data type. It is declared as void * and is used for general purpose storage.
47. What is the main difference between malloc() and calloc() functions in C?
Answer:
Explanation:
Both malloc() and calloc() are used for dynamic memory allocation in C, but calloc() additionally initializes the allocated memory to zero, while malloc() leaves it uninitialized.
48. What does the realloc() function do in C?
Answer:
Explanation:
The realloc() function is used to resize a memory block that was previously allocated with malloc() or calloc(). It allows the memory block to be expanded or contracted, and can move it to a new location if necessary.
49. How do you free dynamically allocated memory in C?
Answer:
Explanation:
Dynamically allocated memory in C must be manually freed using the free() function. This helps prevent memory leaks by releasing memory that is no longer needed.
50. Which of the following is a possible consequence of not freeing memory in a C program?
Answer:
Explanation:
Failing to free memory that has been allocated dynamically (e.g., with malloc() or calloc()) can lead to a memory leak. This is where memory that is no longer needed is not returned to the system, potentially causing a program to consume more and more memory over time.
51. In the context of C programming, what is a memory leak?
Answer:
Explanation:
A memory leak in C programming refers to the failure to free memory that has been allocated dynamically and is no longer needed. Over time, this can cause the program to consume an increasing amount of memory, potentially leading to performance issues or crashes.