Questions: C Programming
Back to Topics List

C Programming Questions

Page 1 of 3 (Displaying Questions 1 – 100 of 249 Total)

1. What is the C programming language?

Show Answer

C is a powerful, general-purpose, and procedural programming language. It is often called a "middle-level" language because it combines the features of high-level languages (like structured control) with the ability to directly manipulate memory (like low-level assembly).

Added: Nov 30, 2025

2. Who designed and developed C?

Show Answer

The C programming language was designed and first implemented by Dennis Ritchie at Bell Labs between 1972 and 1973.

Added: Nov 30, 2025

3. When was C invented?

Show Answer

C was developed in the early 1970s (specifically, 1972-1973). It was primarily created to develop the UNIX operating system.

Added: Nov 30, 2025

4. How does C differ from purely high-level languages like Python or Java?

Show Answer

The key difference is C's use of pointers and its need for explicit memory management. C is compiled directly into machine code, offering superior execution speed and direct control over hardware, which is often abstracted away in higher-level, interpreted languages.

Added: Nov 30, 2025

5. Name three major applications or systems that rely on C.

Show Answer

1. Operating System Kernels (e.g., Linux, macOS, and parts of Windows). 2. Database Systems (e.g., MySQL, PostgreSQL). 3. Compilers, Interpreters, and Assemblers for other programming languages.

Added: Nov 30, 2025

6. What is the significance of the main() function in a C program?

Show Answer

The execution of every C program always starts and ends with the main() function. It serves as the entry point for the operating system to run the program.

Added: Nov 30, 2025

7. What is the primary role of a "header file" (e.g., <stdio.h>)?

Show Answer

A header file contains function declarations, macro definitions, and constants. When you #include a header, you tell the compiler to make those resources (like the printf() function in <stdio.h>) available to your program.

Added: Nov 30, 2025

8. What is the primary difference between a compiler and an interpreter?

Show Answer

A compiler translates the entire source code into machine code before execution, while an interpreter translates and executes code line by line.

Added: Nov 30, 2025

9. What is the significance of the `main()` function in a C program?

Show Answer

Execution of a C program always begins and ends with the `main()` function.

Added: Nov 30, 2025

10. What is the purpose of the `#include <stdio.h>` statement?

Show Answer

It includes the standard input/output header file, which provides functions like `printf()` and `scanf()`.

Added: Nov 30, 2025

11. Explain the difference between call by value and call by reference in C.

Show Answer

Call by value passes a copy of the argument's value, while call by reference passes the address of the argument, allowing the function to modify the original variable.

Added: Nov 30, 2025

12. What is a variable in C?

Show Answer

A variable is a name given to a memory location that stores a piece of data. Its value can change during program execution.

Added: Nov 30, 2025

13. List three basic data types in C.

Show Answer

Integer (`int`), Floating-point (`float`), and Character (`char`).

Added: Nov 30, 2025

14. What is the default initial value of a local variable in C?

Show Answer

The initial value of a local variable is garbage (an unpredictable, unknown value).

Added: Nov 30, 2025

15. What is the difference between the `=` operator and the `==` operator?

Show Answer

The `=` operator is used for assignment, while the `==` operator is used for comparison (checking if two values are equal).

Added: Nov 30, 2025

16. What is type casting in C?

Show Answer

Type casting is the process of converting a variable or expression from one data type to another.

Added: Nov 30, 2025

17. What are the two main types of loops in C for repetition?

Show Answer

Entry-controlled loops (like `for` and `while`) and exit-controlled loops (like `do-while`).

Added: Nov 30, 2025

18. Explain the use of the `break` statement in a loop.

Show Answer

The `break` statement is used to immediately terminate the innermost loop or switch statement.

Added: Nov 30, 2025

19. Explain the use of the `continue` statement in a loop.

Show Answer

The `continue` statement is used to skip the rest of the current iteration of a loop and proceed to the next iteration.

Added: Nov 30, 2025

20. What is an array in C?

Show Answer

An array is a collection of similar data elements stored at contiguous memory locations, referenced by a single name.

Added: Nov 30, 2025

21. How is the size of an array fixed in C?

Show Answer

The size of an array is fixed at compile time (or declaration time) and cannot be changed later.

Added: Nov 30, 2025

22. What is a string in C?

Show Answer

A string in C is an array of characters terminated by a null character (\0).

Added: Nov 30, 2025

23. What header file must be included to use string manipulation functions like `strlen()` and `strcpy()`?

Show Answer

The `<string.h>` header file.

Added: Nov 30, 2025

24. What is a pointer in C?

Show Answer

A pointer is a variable that stores the memory address of another variable.

Added: Nov 30, 2025

25. What is the dereference operator in C, and what does it do?

Show Answer

The dereference operator is `*`. It is used to access the value stored at the memory address held by a pointer.

Added: Nov 30, 2025

26. What is the address-of operator in C, and what does it do?

Show Answer

The address-of operator is `&`. It is used to get the memory address of a variable.

Added: Nov 30, 2025

27. What is a NULL pointer?

Show Answer

A NULL pointer is a pointer that points to no memory location. It is initialized with the value 0 or NULL.

Added: Nov 30, 2025

28. What is a structure (`struct`) in C?

Show Answer

A structure is a user-defined data type that allows you to combine data items of different data types under a single name.

Added: Nov 30, 2025

29. What is a union in C?

Show Answer

A union is similar to a structure, but all members of a union share the same memory location. Only one member can hold a value at any given time.

Added: Nov 30, 2025

30. What is the primary difference between `struct` and `union` in terms of memory?

Show Answer

In a `struct`, memory is allocated for all members separately. In a `union`, all members share the memory of the largest member.

Added: Nov 30, 2025

31. What is the purpose of the `typedef` keyword?

Show Answer

The `typedef` keyword is used to give a new name (an alias) to an existing data type or user-defined type (like a structure).

Added: Nov 30, 2025

32. What is recursion in C?

Show Answer

Recursion is the process where a function calls itself, either directly or indirectly, until a base condition is met.

Added: Nov 30, 2025

33. What is a header file in C?

Show Answer

A header file contains function declarations, macros, and constant definitions that can be included in a C program using the `#include` directive.

Added: Nov 30, 2025

34. What is the role of the `sizeof()` operator?

Show Answer

The `sizeof()` operator is used to determine the size, in bytes, of a variable or data type.

Added: Nov 30, 2025

35. What is a preprocessor directive?

Show Answer

A preprocessor directive is an instruction given to the C preprocessor (e.g., `#include`, `#define`) that is executed before the actual compilation process begins.

Added: Nov 30, 2025

36. What is a macro in C?

Show Answer

A macro is a piece of code that is given a name. Whenever the name is used, the preprocessor replaces it with the actual code.

Added: Nov 30, 2025

37. What is the difference between a global variable and a local variable?

Show Answer

A global variable is declared outside all functions and is accessible from anywhere. A local variable is declared inside a function and is only accessible within that function.

Added: Nov 30, 2025

38. What are storage classes in C?

Show Answer

Storage classes define the scope, visibility, and lifetime of a variable, such as `auto`, `extern`, `static`, and `register`.

Added: Nov 30, 2025

39. What is the use of the `static` storage class?

Show Answer

The `static` storage class retains the value of a variable between function calls and restricts its scope to the file or function where it is declared.

Added: Nov 30, 2025

40. What is the purpose of the `extern` keyword?

Show Answer

The `extern` keyword is used to declare a global variable or function that is defined in another file, making it accessible across multiple source files.

Added: Nov 30, 2025

41. What is dynamic memory allocation in C?

Show Answer

Dynamic memory allocation is the process of allocating memory manually during runtime using functions like `malloc()`, `calloc()`, and `realloc()`.

Added: Nov 30, 2025

42. Which function is used to free dynamically allocated memory?

Show Answer

The `free()` function is used to deallocate (release) the memory previously allocated by `malloc`, `calloc`, or `realloc`.

Added: Nov 30, 2025

43. What is the difference between `malloc()` and `calloc()`?

Show Answer

`malloc()` allocates a single block of requested memory and returns a garbage value. `calloc()` allocates memory for a specified number of blocks and initializes all bytes to zero.

Added: Nov 30, 2025

44. What is file handling in C?

Show Answer

File handling refers to the mechanism that allows a program to read data from a file stored on disk or write data to a file.

Added: Nov 30, 2025

45. What is the file pointer (`FILE *`) used for in file handling?

Show Answer

It is a structure pointer that points to the structure containing all the information about the file, such as its name, location, and reading/writing status.

Added: Nov 30, 2025

46. Which function is used to open a file in C?

Show Answer

The `fopen()` function, which takes the file path and the mode (e.g., "r" for read, "w" for write) as arguments.

Added: Nov 30, 2025

47. What is the significance of the `void` keyword in C?

Show Answer

It indicates that a function does not return any value, or that a function accepts no arguments, or it can be used for generic pointers (`void *`).

Added: Nov 30, 2025

48. What is a dangling pointer?

Show Answer

A dangling pointer is a pointer that points to a memory location that has been deallocated (freed), but the pointer still holds the old address.

Added: Nov 30, 2025

49. What is the scope of a variable?

Show Answer

The scope of a variable defines the region of the program where the variable can be accessed or seen.

Added: Nov 30, 2025

50. What is an L-value and an R-value?

Show Answer

An L-value is an expression that has an address (like a variable name), and an R-value is an expression that has a value but no fixed address (like a constant).

Added: Nov 30, 2025

51. What is the purpose of the `goto` statement?

Show Answer

The `goto` statement is used to transfer control unconditionally from one part of the program to a labeled statement elsewhere in the same function.

Added: Nov 30, 2025

52. What is the difference between `getc()` and `getchar()`?

Show Answer

`getc()` reads a character from a specified file stream, while `getchar()` specifically reads a character from the standard input (`stdin`).

Added: Nov 30, 2025

53. What are the conditional operators (ternary operator) in C?

Show Answer

The conditional operators are `? :` (e.g., `condition ? expression_if_true : expression_if_false`).

Added: Nov 30, 2025

54. What is the associativity of the assignment operator (`=`)?

Show Answer

The assignment operator has right-to-left associativity.

Added: Nov 30, 2025

55. What is an enumeration (`enum`) in C?

Show Answer

An enumeration is a user-defined data type that consists of integral constants, where each constant is given a descriptive name.

Added: Nov 30, 2025

56. What does the term "portability" mean in C programming?

Show Answer

Portability refers to the ability of a C program to be compiled and run on different computer systems or operating systems with little to no modification.

Added: Nov 30, 2025

57. How does the C language treat the logical value true?

Show Answer

The logical value true is represented by any non-zero integer value (usually 1).

Added: Nov 30, 2025

58. How does the C language treat the logical value false?

Show Answer

The logical value false is represented by the integer value 0.

Added: Nov 30, 2025

59. What is a multidimensional array?

Show Answer

A multidimensional array is an array of arrays, most commonly used as a 2D array (a table with rows and columns).

Added: Nov 30, 2025

60. In a function prototype, why is it acceptable to omit parameter names?

Show Answer

The compiler only requires the data types of the parameters to ensure proper function calling, so the names are optional.

Added: Nov 30, 2025

61. What is an inline function?

Show Answer

An inline function is a function whose code is substituted directly at the point of call during compilation, saving the overhead of a regular function call.

Added: Nov 30, 2025

62. What is the escape sequence for a newline character?

Show Answer

The escape sequence for a newline character is `\n`.

Added: Nov 30, 2025

63. What is the escape sequence for the null character?

Show Answer

The escape sequence for the null character is `\0`.

Added: Nov 30, 2025

64. How do you represent a single quote character in a C string literal?

Show Answer

You use the escape sequence `\'` (backslash followed by a single quote).

Added: Nov 30, 2025

65. What is the difference between `printf()` and `puts()`?

Show Answer

`printf()` is used for formatted output and does not automatically add a newline. `puts()` prints a string and automatically adds a newline character at the end.

Added: Nov 30, 2025

66. What is the purpose of the `fflush()` function?

Show Answer

The `fflush()` function is used to clear (flush) the output buffer of a stream, forcing any buffered data to be written immediately.

Added: Nov 30, 2025

67. What is the meaning of the file opening mode "a" in `fopen()`?

Show Answer

The "a" stands for append mode. It opens a file for writing, and all new data is added to the end of the file.

Added: Nov 30, 2025

68. What is an infinite loop?

Show Answer

An infinite loop is a loop whose condition never becomes false, causing it to execute continuously until the program is manually terminated.

Added: Nov 30, 2025

69. What is the function of the `default` case in a `switch` statement?

Show Answer

The `default` case is executed when none of the specified `case` conditions match the expression value.

Added: Nov 30, 2025

70. Can a C function return multiple values?

Show Answer

No, a C function can only return one value directly. To return multiple values, you must use pointers or structures.

Added: Nov 30, 2025

71. What is a nested loop?

Show Answer

A nested loop is a loop inside another loop. The inner loop executes completely for every single execution of the outer loop.

Added: Nov 30, 2025

72. What are command-line arguments in C?

Show Answer

Command-line arguments are data passed to the main function of a program when it is executed from the command line, received via `argc` and `argv`.

Added: Nov 30, 2025

73. What is the data type of the `argv` parameter in the `main` function?

Show Answer

The `argv` parameter is an array of strings (or `char *argv[]`).

Added: Nov 30, 2025

74. What is the meaning of the `const` keyword in C?

Show Answer

The `const` keyword is used to declare a variable as a constant, meaning its value cannot be changed after initialization.

Added: Nov 30, 2025

75. What is a constant (literal) in C?

Show Answer

A constant is a value that cannot be changed during the execution of a program.

Added: Nov 30, 2025

76. What is the difference between a constant and a variable in terms of modification?

Show Answer

A variable's value can be changed, while a constant's value is fixed and cannot be modified.

Added: Nov 30, 2025

77. What are operators in C?

Show Answer

Operators are symbols that tell the compiler to perform specific mathematical, relational, or logical operations.

Added: Nov 30, 2025

78. List three types of relational operators in C.

Show Answer

Greater than (`>`), Less than (`<`), Equal to (`==`), or Not equal to (`!=`). (Any three are acceptable).

Added: Nov 30, 2025

79. What is a bitwise operator?

Show Answer

A bitwise operator works on individual bits of its operands (e.g., AND `&`, OR `|`, XOR `^`).

Added: Nov 30, 2025

80. What is operator precedence?

Show Answer

Operator precedence determines the order in which operators in an expression are evaluated.

Added: Nov 30, 2025

81. What is the purpose of using parentheses `()` in an expression?

Show Answer

Parentheses are used to group terms and override the default operator precedence.

Added: Nov 30, 2025

82. What is the use of the `_Bool` data type (or `bool` in C99)?

Show Answer

The `_Bool` data type is used to store boolean values, which can only be `true` (1) or `false` (0).

Added: Nov 30, 2025

83. What is the function of the `exit()` function?

Show Answer

The `exit()` function is used to terminate the execution of the entire C program immediately, regardless of where it is called.

Added: Nov 30, 2025

84. What header file must be included to use the dynamic memory allocation functions?

Show Answer

The `<stdlib.h>` header file.

Added: Nov 30, 2025

85. What does the acronym K&R C refer to?

Show Answer

K&R C refers to the original specification of the C language as described in "The C Programming Language" book by Kernighan and Ritchie.

Added: Nov 30, 2025

86. What is the purpose of the semicolon `;` in C?

Show Answer

The semicolon is used to mark the end of a statement.

Added: Nov 30, 2025

87. What is the maximum size of a `char` data type?

Show Answer

A `char` data type is typically 1 byte (8 bits).

Added: Nov 30, 2025

88. What is the main advantage of using an array instead of individual variables?

Show Answer

Arrays allow you to manage and process a large number of related variables efficiently using loops and indexing.

Added: Nov 30, 2025

89. How do you access the elements of a structure?

Show Answer

Elements of a structure are accessed using the dot (`.`) operator (for a structure variable) or the arrow (`->`) operator (for a structure pointer).

Added: Nov 30, 2025

90. What is the correct format specifier for printing a `float` value?

Show Answer

The correct format specifier is `%f`.

Added: Nov 30, 2025

91. What is the correct format specifier for printing an `int` value?

Show Answer

The correct format specifier is `%d` or `%i`.

Added: Nov 30, 2025

92. What is the correct format specifier for printing a pointer address?

Show Answer

The correct format specifier is `%p`.

Added: Nov 30, 2025

93. In `scanf()`, what is the purpose of the address-of operator (`&`)?

Show Answer

It passes the memory address of the variable to `scanf()`, allowing the function to store the input value directly into that variable.

Added: Nov 30, 2025

94. What is the difference between `gets()` and `fgets()`?

Show Answer

`gets()` reads an entire line from standard input but is unsafe as it has no buffer size limit. `fgets()` is safer as it takes a buffer size limit and specifies the input stream.

Added: Nov 30, 2025

95. What is the advantage of using `register` variables?

Show Answer

They suggest to the compiler that the variable should be stored in a CPU register for faster access, though the compiler may ignore the suggestion.

Added: Nov 30, 2025

96. Can a C program be compiled without the `main()` function?

Show Answer

Yes, it can be compiled, but it cannot be executed without a definition for the `main()` function.

Added: Nov 30, 2025

97. What is the role of `argc` in command-line arguments?

Show Answer

`argc` (argument count) is an integer that stores the total number of command-line arguments passed to the program.

Added: Nov 30, 2025

98. What is the largest integer type in C?

Show Answer

The `long long int` or `long long` type (C99 standard or later).

Added: Nov 30, 2025

99. What is a dangling `else` problem?

Show Answer

It is a common ambiguity in programming where it is unclear which `if` statement an `else` clause belongs to. In C, the `else` always binds to the nearest preceding unmatched `if`.

Added: Nov 30, 2025

100. What is a function prototype?

Show Answer

A function prototype is a declaration of a function that specifies the function's name, return type, and parameter types, allowing the compiler to perform type checking.

Added: Nov 30, 2025