Wednesday, October 1, 2025

C Interview Questions & Answers || Freshers Level || Set - I

 Question: 1. List the data types supported in the C Language. 

Answer: The data types supported in the C Programming Language are:

  • Int: Used to store integers (e.g., int var = 10;).

  • Float: Used to store floating/decimal numbers (e.g., float weight = 10.5;).

  • Char: Used to store characters (e.g., char Grade = ‘A’;).

  • Double: Used to store double-precision floating-point numbers (e.g., double pi = 3.14159265359;).

  • Void: Used for functions that do not return any value (e.g., void function_name() { return; }).

Question: 2. Explain the working of printf() and scanf() functions in C Programming language? 

Answer:

  • printf() is used to print the value or display the output on the screen (e.g., printf("Hello, Intellipaat !");).

  • scanf() is used to take input from the user (e.g., scanf("%d", &intellipaat_marks);).

Question: 3. Difference between "=" and "==" operator in C programming. 

Answer:

  • “=” operator is used to assign values (e.g., int var = 10;).

  • “==” operator is used to compare two values (e.g., if(var1 == var2) { printf("%d", var1); }).

Question: 4. What are Reserved Keywords in C? 

Answer: Reserved keywords are special keywords that cannot be used as a variable name. Examples include int, return, for, void, if, else, and switch.

Question: 5. What is the use of static variables in C? 

Answer: Static variables are initialized only once and retain their previous values which were assigned or initialized in the previous scope.

Question: 6. What do you mean by the scope of the variable? 

Answer: The scope of a variable means the section of the code in which the variable is accessible or valid. Variables can have global scope (e.g., int globalVar = 10;) or local scope (e.g., int localVar = 5; inside a function).

Question: 7. Explain the difference between #include "..." and #include <...> header files? 

Answer:

  • #include “…” is used to include user-defined header files (e.g., #include "myHeader.h").

  • #include <…> is used to include standard library header files (e.g., #include <stdio.h>).

Question: 8. What are the different storage class specifiers in the C Language? 

Answer: There are 4 storage class specifiers in the C Language: auto, register, static, and extern.

  • Auto is used as the default storage class for local variables.

  • The register is used to store variables in the CPU register for faster access.

  • Static is used to retain the value of variables between function calls.

  • Extern is used to declare a global variable or function in another file.

Question: 9. What is a structure? 

Answer: A structure is a user-defined data type used to combine or merge multiple data types together (e.g., defining struct Person with a char name; and an int age;).

Question: 10. What is a UNION? 

Answer: A Union is similar to a structure, but unlike a structure where variables do not share memory, in a union, multiple variables with different data types use shared memory.

Question: 11. What is the difference between macro and functions? 

Answer:

  • Macros are preprocessor directives defined using the #define keyword. They are written before the main function and are executed first.

  • Functions are blocks of code that are executed during run-time.

Question: 12. What is the difference between deep copy and shallow copy in C? 

Answer:

Feature

Shallow Copy

Deep Copy

Definition

Copies only the pointer, not the actual data it points to.

Copies both the pointer and the actual data (creates a new memory block).

Memory Usage

Lower (shares the same memory address).

Higher (allocates separate memory).

Data Independence

No – Changes in one reflect in the other.

Yes – Changes are isolated.

Use Case

When objects are not managing dynamic memory.

When objects manage resources like heap memory.

Question: 13. Write a program to print "Hello-World" without using a semicolon. 

Answer: A program to print "Hello-World" without a semicolon is covered in the sources, but the explicit code is not provided in text form.

Question: 14. How to convert a string to a number in C? 

Answer: To convert a string into a number, the atoi() function (ASCII to integer) is used. This function is defined in the stdlib.h header.

Question: 15. How to convert a number to a string in C? 

Answer: The source material covers converting a number to a string in C, but the specific implementation details or function names are shown only through a code example.

Question: 16. What is the difference between malloc() and calloc() in the C programming language? 

Answer:

  • Malloc() is used to dynamically allocate memory but does not initialize it (e.g., int* ptr = (int*)malloc(4 * sizeof(int));).

  • Calloc() is used to dynamically allocate memory and initializes it to 0 (e.g., int* ptr = (int*)calloc(4, sizeof(int));).

Question: 17. What are an r-value and an l-value? 

Answer:

  • An L-value (Left-value) is an object that has a specified memory location and is written on the left side of the assignment (e.g., int var = 5; where var is the l-value).

  • An R-value (Right-value) is an object that does not have a specified memory location and is written on the right side of the assignment (e.g., int var = var1 + 5; where var1 + 5 is the r-value).

Question: 18. What is the difference between a null pointer and a void pointer? 

Answer:

  • A NULL Pointer is a pointer that points to nothing (e.g., int* ptr = NULL;).

  • A Void Pointer is a pointer that can point to any data type.

Question: 19. What is the difference between const char* p and char const* p? Answer: There is no difference between const char* p and char const* p. Both statements mean that p is a pointer to a constant character, which implies that the character cannot be modified through the pointer p.

Question: 20. How does C23 improve memory safety or standard library features? 

Answer: The latest version of C (C23) implements new features to improve safety and user-friendliness. Key improvements include:

  • Buffer protective features: New functions like strcpy_s and memcpy_s handle preexisting buffer problems, such as buffer overflows. For instance, strcpy_s() checks the size of the destination memory space, preventing errors that occurred with older functions like strcpy().

  • Better null pointer support: C23 introduces nullptr, which reduces mistakes and clarifies code when working with pointers.

  • Improved standard library: Enhancements add helpful functions and additional security checks to streamline development and improve speed and safety.

Question: 21. What is the difference between getc(), getchar(), getch(), and getche() in C? 

Answer:

  • getc() is used to read a single character from a file, standard input (stdin), or any input stream (Syntax: int getc(FILE *stream);).

  • getchar() is used to read a single character from the standard input (Syntax: int getchar(void);).

  • getch() reads a single character from the keyboard but does not display the character on the screen (Syntax: int getch();).

  • getche() reads a single character from the keyboard and displays the character immediately on the output screen (Syntax: int getche(void);).

…till next post, bye-bye & take care.

No comments:

Post a Comment