SEO-friendly, mobile-ready page with clean UI. Correct answers highlighted.
C is a general-purpose, procedural programming language developed by Dennis Ritchie at Bell Labs in the early 1970s. It provides low-level access to memory, efficient mapping to machine instructions, and is widely used for system programming, embedded systems, and performance-critical applications.
A C program consists of functions and declarations. Execution begins at main()
. Statements end with semicolons.
// basic structure
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}
Primary types: int
, char
, float
, double
. Use sizeof()
to find storage size. Qualifiers: short
, long
, signed
, unsigned
.
Arithmetic, relational, logical, bitwise, assignment, and ternary (?:
) operators. Precedence matters; use parentheses to clarify.
Conditional statements: if
, if-else
, switch
. Loops: for
, while
, do-while
. Use break
and continue
.
Declare prototypes, define functions, pass by value (C passes arguments by value). For arrays/large data, pass pointers.
int add(int a, int b) { return a + b; }
Arrays: contiguous memory for elements of same type. Strings are arrays of char
terminated by '\0'. Use functions in <string.h>
like strcpy
, strlen
.
A pointer stores memory address. Pointer arithmetic, dereference (*
), address operator (&
). Pointers to pointers and function pointers exist. Understand NULL
and pointer safety.
int x=10; int *p = &x; printf("%d", *p); // prints 10
struct
groups related variables; union
shares memory for members. Use typedef
for readability.
Use malloc
, calloc
, realloc
and free memory with free()
. Avoid memory leaks and dangling pointers.
Use fopen
, fclose
, fread
, fwrite
, fprintf
, fscanf
. Check for NULL file pointers.
Directives: #include
, #define
, #ifdef
. Used for macros and conditional compilation.
Compile: gcc -o prog prog.c
. Compilation stages: preprocessing, compilation, assembly, linking. Use -Wall
to enable warnings. Debug using gdb
or printf
debugging, and tools like Valgrind for memory issues.
1. Who developed the C programming language?
2. Which function is the entry point of a C program?
3. Which header file is required for printf?
4. Which of the following is a valid variable name in C?
5. Size of int on a typical 32-bit system is:
6. What does the '*' operator denote in declarations like int *p;
?
7. String in C is terminated by:
8. Which declaration declares an array of 10 integers?
9. By default, arguments in C are passed by:
10. Which function allocates memory dynamically?
11. Which function releases memory allocated by malloc?
12. What does sizeof(char) typically return?
13. Which directive includes a header file?
14. What is typedef used for?
15. How do you access members of a struct through pointer p?
16. An enum in C is used to:
17. What is NULL?
18. Which operator gives the address of a variable?
19. Which has higher precedence?
20. Which loop will execute body at least once?
21. Which function reads formatted input from stdin?
22. What is the format specifier for double?
23. fopen with mode "r" does what?
24. Standard error stream is:
25. A macro is defined using:
26. The qualifier 'const' means:
27. Static variable inside a function retains its value between calls. True or false?
28. Which operator performs bitwise AND?
29. sizeof operator returns size in:
30. volatile keyword tells compiler that variable may change unexpectedly. This prevents optimization. True or false?
31. In old C, function declarations without return type defaulted to int. Modern compilers warn against this. True?
32. A function pointer can be used to:
33. Recursion is:
34. Segmentation fault often occurs due to:
35. Linker stage does:
36. Which header provides malloc and free?
37. getchar() reads from:
38. Pointer arithmetic increments by size of pointed type. True or false?
39. fopen mode "w" will:
40. Macro vs function: macro is expanded by preprocessor. True or false?
41. sizeof returns size for types and expressions. It is evaluated at compile time for types. True?
42. Implicit type conversion is called:
43. Left shifting 1 by 3 (1<<3) gives:
44. errno is used to:
45. Undefined behavior in C means compiler may do anything. True or false?
46. Reentrant function is safe to call from signal handlers. True?
47. Which header provides fixed width integer types like int32_t?
48. fflush(stdout) is used to:
49. exit(0) indicates successful termination. True?
50. Which function compares two memory blocks?