Here’s a list of 100 Important C language questions with their answers. I have categorized them into sections for better clarity.


100 Important C language questions with their answers
100 Important C language questions with their answers

Basic Concepts

(100 Important C language questions with their answers)

  1. What is C language?
    Answer: C is a general-purpose, procedural programming language developed by Dennis Ritchie in the 1970s at Bell Labs.
  2. What are keywords in C?
    Answer: Keywords are reserved words in C, predefined by the language, such as int, return, if, while, etc.
  3. What is the difference between int and float?
    Answer:

    • int is used for integer values.
    • float is used for decimal or floating-point values.
  4. What is a variable?
    Answer: A variable is a storage location in memory with a name and a type to store data.
  5. What is a constant in C?
    Answer: A constant is a value that cannot be changed during the execution of a program.

Data Types and Operators

(100 Important C language questions with their answers)

  1. List the basic data types in C.
    Answer: int, float, char, double.
  2. What are derived data types in C?
    Answer: Arrays, pointers, structures, and unions.
  3. What is the purpose of the sizeof() operator?
    Answer: It returns the size (in bytes) of a data type or variable.
  4. What is typecasting?
    Answer: Typecasting is converting a variable from one data type to another.
  5. What is the difference between = and ==?
    Answer:
  • = is the assignment operator.
  • == is the equality operator for comparison.

Control Structures

(100 Important C language questions with their answers)

  1. What is an if-else statement?
    Answer: It is a conditional statement that executes a block of code if the condition is true, and another block if it is false.
  2. What is a switch statement?
    Answer: A multi-way decision-making statement to execute one block of code among many options.
  3. What is the difference between while and do-while?
    Answer:
  • while: Executes the block if the condition is true.
  • do-while: Executes the block at least once, then checks the condition.
  1. What is the syntax of a for loop?
    Answer:
for (initialization; condition; increment/decrement) {
    // Code block
}
  1. What is a nested loop?
    Answer: A loop inside another loop.

Functions

(100 Important C language questions with their answers)

  1. What is a function in C?
    Answer: A block of code that performs a specific task and can be reused.
  2. What is the difference between call by value and call by reference?
    Answer:
  • Call by value: Copies the value of the argument.
  • Call by reference: Passes the address of the argument.
  1. What is the return type of main() in C?
    Answer: int.
  2. What is a recursive function?
    Answer: A function that calls itself.
  3. How do you declare a function in C?
    Answer:
return_type function_name(parameters);

Pointers

(100 Important C language questions with their answers)

  1. What is a pointer?
    Answer: A pointer is a variable that stores the address of another variable.
  2. How do you declare a pointer?
    Answer: int *ptr;
  1. What is the NULL pointer?
    Answer: A pointer that does not point to any memory location.
  2. What is pointer arithmetic?
    Answer: Operations like addition or subtraction performed on pointers.
  3. What is a void pointer?
    Answer: A pointer that can hold the address of any data type.

Arrays and Strings

(100 Important C language questions with their answers)

  1. What is an array in C?
    Answer: A collection of elements of the same data type stored in contiguous memory locations.
  2. How do you declare an array?
    Answer:int arr[10];
  1. What is a multidimensional array?
    Answer: An array with more than one dimension, such as a matrix.
  2. How do you declare a string in C?
    Answer:char str[20];
  1. What is the strlen() function?
    Answer: It returns the length of a string.

Structures and Unions

(100 Important C language questions with their answers)

  1. What is a structure in C?
    Answer: A user-defined data type to group different types of variables.
  2. How do you declare a structure?
    Answer:
struct struct_name {
    int x;
    char y;
};
  1. What is the difference between structure and union?
    Answer:
  • Structure: Allocates memory for all members.
  • Union: Allocates shared memory for all members.
  1. What is the syntax for accessing structure members?
    Answer:
structure_variable.member_name;
  1. How do you define a union?
    Answer:
union union_name {
    int x;
    char y;
};

Advanced Topics

(100 Important C language questions with their answers)

  1. What is dynamic memory allocation?
    Answer: Allocating memory at runtime using functions like malloc(), calloc(), realloc(), and free().
  2. What is a file in C?
    Answer: A storage medium for saving data.
  3. How do you open a file in C?
    Answer:
FILE *fp = fopen("filename.txt", "mode");
  1. What is a preprocessor directive?
    Answer: Instructions processed before compilation, starting with #, like #include.
  2. What is a macro?
    Answer: A preprocessor directive for defining constants or expressions using #define.

Common Errors and Debugging

(100 Important C language questions with their answers)

  1. What is a syntax error?
    Answer: An error in the code structure or grammar.
  2. What is a segmentation fault?
    Answer: An error caused by accessing memory not allocated to the program.
  3. What is an infinite loop?
    Answer: A loop that never terminates due to incorrect conditions.
  4. What is the difference between a compiler and an interpreter?
    Answer:
  • Compiler: Converts entire code into machine code at once.
  • Interpreter: Executes code line by line.
  1. What is debugging?
    Answer: The process of identifying and fixing errors in a program.


    Dynamic Memory Allocation

    (100 Important C language questions with their answers)

    1. What is the malloc() function?
      Answer: malloc() allocates memory dynamically and returns a pointer to the allocated memory. Syntax:
    ptr = (type*)malloc(size);
    
    1. What is the difference between malloc() and calloc()?
      Answer:
    • malloc(): Allocates a single block of memory.
    • calloc(): Allocates multiple blocks of memory and initializes them to zero.
    1. What does free() do?
      Answer: free() deallocates previously allocated memory.
    2. What is realloc() used for?
      Answer: realloc() resizes the memory block allocated by malloc() or calloc().
    3. Why is dynamic memory allocation important?
      Answer: It allows efficient use of memory by allocating memory as needed during program execution.

    Files in C

    (100 Important C language questions with their answers)

    1. What are the different modes to open a file?
      Answer:
    • "r": Read
    • "w": Write
    • "a": Append
    • "r+": Read and write
    1. How do you close a file?
      Answer:
    fclose(file_pointer);
    
    1. What is the purpose of fscanf() and fprintf()?
      Answer:
    • fscanf(): Reads data from a file.
    • fprintf(): Writes data to a file.
    1. What is the difference between fgetc() and fgets()?
      Answer:
    • fgetc(): Reads a single character from a file.
    • fgets(): Reads a string from a file.
    1. What is the use of feof()?
      Answer: Checks if the end of the file has been reached.

    Storage Classes

    (100 Important C language questions with their answers)

    1. What are storage classes in C?
      Answer: Storage classes define the scope, visibility, and lifetime of variables.
    2. List the types of storage classes in C.
      Answer:
    • auto
    • register
    • static
    • extern
    1. What is the difference between auto and register?
      Answer:
    • auto: Default storage class for local variables.
    • register: Suggests storing the variable in a CPU register for faster access.
    1. What is the purpose of the static keyword?
      Answer: The static keyword retains a variable’s value between function calls.
    2. What is the extern keyword?
      Answer: Declares a global variable or function in another file.

    Preprocessor Directives

    (100 Important C language questions with their answers)

    1. What is the use of #include?
      Answer: Includes the contents of a file (usually header files) in the program.
    2. What does #define do?
      Answer: Defines a macro or constant.
    3. What is the purpose of #undef?
      Answer: Undefines a macro.
    4. What is a conditional compilation?
      Answer: Compilation based on conditions using directives like #ifdef, #ifndef, etc.
    5. What is the difference between #ifdef and #ifndef?
      Answer:
    • #ifdef: Compiles the code if the macro is defined.
    • #ifndef: Compiles the code if the macro is not defined.

    Functions

    (100 Important C language questions with their answers)

    1. What is the default return type of a function in C?
      Answer: int.
    2. Can a function return multiple values in C?
      Answer: No, but you can use pointers or structures to achieve this.
    3. What is the scope of a local variable?
      Answer: Limited to the block or function where it is declared.
    4. What is a global variable?
      Answer: A variable declared outside all functions, accessible throughout the program.
    5. What is function overloading?
      Answer: C does not support function overloading; it’s a feature of C++ or other languages.

    Bitwise Operators

    (100 Important C language questions with their answers)

    1. What is the purpose of the & operator?
      Answer: Bitwise AND.
    2. What is the purpose of the | operator?
      Answer: Bitwise OR.
    3. What is the purpose of the ^ operator?
      Answer: Bitwise XOR.
    4. What is the purpose of the ~ operator?
      Answer: Bitwise NOT.
    5. What is a bitwise shift operator?
      Answer:
    • <<: Left shift.
    • >>: Right shift.

    Error Handling

    (100 Important C language questions with their answers)

    1. What is an error in C?
      Answer: A mistake in the program that prevents it from executing correctly.
    2. What are the types of errors in C?
      Answer:
    • Syntax errors
    • Runtime errors
    • Logical errors
    1. What is the purpose of perror()?
      Answer: Displays a descriptive error message.
    2. What is the errno variable?
      Answer: A global variable used to indicate error codes.
    3. How do you handle errors in C?
      Answer: Using error-checking mechanisms like if conditions and errno.

    Miscellaneous (100 Important C language questions with their answers)

    1. What is a typedef in C?
      Answer: Used to create a new name for an existing type.
    2. What is the purpose of the const keyword?
      Answer: Declares variables that cannot be modified.
    3. What is the difference between break and continue?
      Answer:
    • break: Exits a loop or switch.
    • continue: Skips the current iteration of a loop.
    1. What is the purpose of goto?
      Answer: Transfers control to a labeled statement.
    2. What is a command-line argument?
      Answer: Arguments passed to the program at the time of execution.

    Programming Questions

    (100 Important C language questions with their answers)

    1. Write a program to check if a number is even or odd.
    #include <stdio.h>
    int main() {
        int num;
        printf("Enter a number: ");
        scanf("%d", &num);
        if (num % 2 == 0)
            printf("Even\n");
        else
            printf("Odd\n");
        return 0;
    }
    
    1. Write a program to calculate the sum of digits of a number.
    #include <stdio.h>
    int main() {
        int num, sum = 0, digit;
        printf("Enter a number: ");
        scanf("%d", &num);
        while (num > 0) {
            digit = num % 10;
            sum += digit;
            num /= 10;
        }
        printf("Sum of digits: %d\n", sum);
        return 0;
    }
    
    1. Write a program to reverse a string.
    #include <stdio.h>
    #include <string.h>
    int main() {
        char str[100], temp;
        int i, len;
        printf("Enter a string: ");
        gets(str);
        len = strlen(str);
        for (i = 0; i < len / 2; i++) {
            temp = str[i];
            str[i] = str[len - i - 1];
            str[len - i - 1] = temp;
        }
        printf("Reversed string: %s\n", str);
        return 0;
    }
    

    Key Concepts

    (100 Important C language questions with their answers)

    1. What is the difference between char and string?
      Answer:
    • char: Stores a single character.
    • string: Stores a sequence of characters (array of char).
    1. What is a dangling pointer?
      Answer: A pointer pointing to memory that has already been freed.
    2. What is the difference between exit() and return?
      Answer:
    • exit(): Terminates the program immediately.
    • return: Exits a function and returns a value.
    1. What is the stack in C?
      Answer: A memory segment for local variables and function calls.
    2. What is a heap in C?
      Answer: A memory segment for dynamic memory allocation.

     

Mahindra Electric Vehicles

How to build a website and make money 

Kia sonet


 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top