C Language – 50 Q&A Practice

1. What is C language?

Answer: C is a general-purpose programming language developed by Dennis Ritchie in 1972.

Note: Used for system programming like OS and embedded systems.

2. Who developed C language?

Answer: Dennis Ritchie developed C at Bell Labs.

Note: He also contributed to UNIX.

3. What is the extension of C files?

Answer: .c

Note: Example: program.c

4. What is the entry point of a C program?

Answer: main() function.

Note: Every C program starts execution from main().

5. What is a variable?

Answer: A variable stores data in memory.

Note: Example: int a = 10;

6. What are data types in C?

Answer: int, float, char, double.

Note: They define the type of data stored.

7. What is printf()?

Answer: A function used to print output.

Note: Defined in stdio.h

8. What is scanf()?

Answer: Used to take input from the user.

Note: Example: scanf('%d', &a);

9. What is a pointer?

Answer: A variable that stores the address of another variable.

Note: Example: int *p;

10. What is an array?

Answer: A collection of elements of the same data type stored in contiguous memory.

Note: Example: int arr[5];

11. What is a function?

Answer: A block of code that performs a specific task and can be reused.

Note: Example: int add(int a, int b);

12. What is a loop?

Answer: A control structure that repeats a block of code multiple times.

Note: Types: for, while, do-while.

13. What is recursion?

Answer: A function calling itself.

Note: Example: factorial using recursion.

14. What is a structure?

Answer: A user-defined data type that groups variables of different types.

Note: Example: struct Student { int id; char name[20]; };

15. What is a union?

Answer: A user-defined data type where all members share the same memory location.

Note: Used for memory optimization.

16. What is a string in C?

Answer: A sequence of characters terminated by a null character.

Note: Example: char name[] = "Sunitha";

17. What is a header file?

Answer: A file that contains function declarations and macros.

Note: Example: stdio.h

18. What is a macro?

Answer: A fragment of code defined using #define.

Note: Example: #define PI 3.14

19. What is dynamic memory allocation?

Answer: Allocating memory during program execution.

Note: Functions: malloc(), calloc(), realloc(), free().

20. What is malloc()?

Answer: A function used to allocate memory dynamically.

Note: Example: ptr = (int*)malloc(sizeof(int));

21. What is calloc()?

Answer: Allocates memory and initializes it to zero.

Note: Example: ptr = (int*)calloc(5, sizeof(int));

22. What is realloc()?

Answer: Resizes previously allocated memory.

Note: Example: realloc(ptr,newsize);

23. What is free()?

Answer: Used to release dynamically allocated memory.

Note: Example: free(ptr);

24. What is file handling?

Answer: Reading and writing data to files.

Note: Functions: fopen(), fclose(), fprintf(), fscanf().

25. What is fopen()?

Answer: Opens a file.

Note: Example: fopen("file.txt","r");

26. What is fclose()?

Answer: Closes an opened file.

Note: Example: fclose(fp);

27. What is fprintf()?

Answer: Writes formatted output to a file.

Note: Similar to printf.

28. What is fscanf()?

Answer: Reads formatted input from a file.

Note: Similar to scanf.

29. What is a global variable?

Answer: A variable declared outside all functions.

Note: Accessible throughout the program.

30. What is a local variable?

Answer: A variable declared inside a function.

Note: Accessible only within that function.

31. What is a static variable?

Answer: A variable that retains its value between function calls.

Note: Declared using static keyword.

32. What is the sizeof operator?

Answer: Used to determine the size of a data type.

Note: Example: sizeof(int)

33. What is type casting?

Answer: Converting one data type into another.

Note: Example: (float)a

34. What is ASCII?

Answer: Character encoding standard.

Note: Example: ASCII value of A = 65

35. What is a compiler?

Answer: Software that converts C code into machine code.

Note: Example: GCC compiler.

36. What is debugging?

Answer: Process of finding and fixing errors.

Note: Helps improve program correctness.

37. What is an algorithm?

Answer: Step-by-step solution to a problem.

Note: Used before writing code.

38. What is a flowchart?

Answer: Graphical representation of an algorithm.

Note: Helps visualize logic.

39. What is a segmentation fault?

Answer: Error caused by invalid memory access.

Note: Often caused by incorrect pointers.

40. What is a dangling pointer?

Answer: Pointer pointing to freed memory.

Note: Dangerous in programs.

41. What is a null pointer?

Answer: Pointer that points to nothing.

Note: Example: int *ptr = NULL;

42. What is pointer arithmetic?

Answer: Operations performed on pointer variables.

Note: Example: ptr++

43. What is a command line argument?

Answer: Arguments passed to the program when executing.

Note: Example: int main(int argc, char *argv[])

44. What is the difference between call by value and call by reference?

Answer: Call by value passes a copy; call by reference passes address.

Note: Use & operator for reference.

45. What is an IDE?

Answer: Software used to write and run programs.

Note: Example: VS Code, CodeBlocks.

46. What is break?

Answer: Terminates a loop or switch.

Note: Used inside loops or switch statements.

47. What is continue?

Answer: Skips current iteration and continues the loop.

Note: Used inside loops.

48. What is a do-while loop?

Answer: Executes code at least once and then checks condition.

Note: Syntax: do { } while(condition);

49. What is a while loop?

Answer: Executes a block while condition is true.

Note: Syntax: while(condition) { }

50. What is a for loop?

Answer: Executes a block a known number of times.

Note: Syntax: for(initial; condition; increment) { }