NextGen Placement Pro Program
Interview Preparation Module
Programming for problem
solving
B.Tech-1st Semester
Contents
1. Interview Questions with Answers(UNIT 1) 2
2. Interview Questions and Answers (UNIT 2) 3
3. Interview Questions and Answers(UNIT 3) 5
4. Interview Questions and Answers (UNIT 4) 7
5. Interview Questions and Answers (UNIT 5) 8
1
1. Interview Questions with Answers(UNIT 1)
1. What are the main components of a computer system?
Answer:
The main components of a computer system include:
• Hardware: Physical parts like CPU, keyboard, mouse, monitor, etc.
• Software: Programs and operating systems that run on hardware.
• Firmware: Pre-installed software in ROM.
• Users: People who interact with the computer.
2. What is the difference between hardware and software?
Answer:
• Hardware is the physical, tangible part of a computer (e.g., CPU, RAM, monitor).
• Software is a set of instructions that tell the hardware what to do (e.g., Windows OS, MS
Word, C++ compiler).
3. Define algorithm. What are the key characteristics of a good algorithm?
Answer:
An algorithm is a finite sequence of well-defined steps for solving a problem.
Characteristics:
(a) Finiteness – Must terminate after a finite number of steps
(b) Definiteness – Each step is precisely defined
(c) Input – Accepts zero or more inputs
(d) Output – Produces at least one output
(e) Effectiveness – Basic and feasible steps
4. Differentiate between compiler and interpreter.
Answer:
• Compiler: Converts the entire high-level program into machine code before execution.
• Interpreter: Translates and executes the program line-by-line.
Example:
• C uses a compiler.
• Python uses an interpreter.
5. What is the function of an assembler?
Answer:
An assembler converts assembly language code (mnemonics) into machine language (binary
code) that the CPU can execute.
6. Explain the purpose of linker and loader in program execution.
Answer:
• Linker: Combines multiple object files and libraries into a single executable file.
• Loader: Loads the executable file into memory and prepares it for execution.
7. What is a flowchart? Name some commonly used symbols.
Answer:
A flowchart is a graphical representation of an algorithm.
Common symbols used:
• Terminator (Oval): Start/End
• Process (Rectangle): Operation
• Decision (Diamond): Yes/No
• Input/Output (Parallelogram): Data entry or display
• Arrow: Flow of control
8. What are complexity notations in algorithms?
Answer:
Complexity notations describe the performance of an algorithm:
• Big O (O): Worst-case performance
• Omega (Ω): Best-case performance
• Theta (Θ): Average-case or tight bound
9. Write a simple algorithm to check whether a number is even or odd.
Answer:
Algorithm:
(a) Start
(b) Read number
(c) If number % 2 == 0, then
• Print “Even”
(d) Else
• Print “Odd”
(e) End
10. List and explain the types of programming languages.
Answer:
• Machine Language: Binary code directly understood by the CPU.
• Assembly Language: Uses mnemonics; needs an assembler to convert into machine code.
• High-Level Language: Human-readable programming languages like C, Java, Python;
require compiler/interpreter.
2. Interview Questions and Answers (UNIT 2)
1. What are the key features of the C programming language?
Answer:
• Simple and efficient syntax
• Structured and procedural programming
• Portable and machine-independent
• Allows direct memory access using pointers
• Rich set of operators and library functions
2. Explain the basic structure of a C program.
Answer: A C program typically contains the following parts:
• Preprocessor directives (e.g., #include<stdio.h>)
• main() function as the entry point
• Variable declarations
• Executable statements (logic, loops, I/O)
• Return statement (e.g., return 0;)
Example:
# include < stdio .h >
int main () {
printf ( " Hello , World ! " ) ;
return 0;
}
3. What are tokens in C? List the types.
Answer: Tokens are the smallest elements of a C program. Types of tokens include:
• Keywords
• Identifiers
• Constants
• Operators
• Strings
• Special symbols
4. Differentiate between while and do-while loops in C.
Answer:
• while loop: Condition is checked before executing the loop body.
• do-while loop: Loop body is executed first, then the condition is checked.
Example of while loop:
int i = 0;
while ( i < 5) {
printf ( " % d \ n " , i ) ;
i ++;
}
Example of do-while loop:
int i = 0;
do {
printf ( " % d \ n " , i ) ;
i ++;
} while ( i < 5) ;
5. What is type conversion in C? Explain the types.
Answer: Type conversion refers to converting one data type to another. It is of two types:
• Implicit conversion: Done automatically by the compiler (e.g., int to float).
• Explicit conversion (type casting): Done manually by the programmer using cast
operators.
Example:
float x ;
int a = 5 , b = 2;
x = ( float ) a / b ; // Explicit conversion
6. Explain the use of break and continue statements.
Answer:
• break: Terminates the nearest enclosing loop or switch statement.
• continue: Skips the current iteration and proceeds to the next iteration of the loop.
Example using break:
for ( int i =0; i <10; i ++) {
if ( i == 5) break ;
printf ( " % d " , i ) ;
}
Example using continue:
for ( int i =0; i <10; i ++) {
if ( i == 5) continue ;
printf ( " % d " , i ) ;
}
3. Interview Questions and Answers(UNIT 3)
1. What is the difference between 1-D and 2-D arrays? Give examples.
Answer:
• A 1-D array is a list of elements stored in a single row. Example:
int numbers [5] = {1 , 2 , 3 , 4 , 5};
• A 2-D array is a matrix (table) of elements stored in rows and columns. Example:
int matrix [2][3] = {{1 , 2 , 3} , {4 , 5 , 6}};
2. Differentiate between character arrays and strings in C.
Answer:
• A character array is a sequence of characters without necessarily ending in ‘\0‘. Example:
‘char ch[5] = ’H’, ’e’, ’l’, ’l’, ’o’;‘
• A string is a character array terminated by a null character ‘\0‘. Example: ‘char str[] =
”Hello”;‘
3. What are the different types of functions in C?
Answer:
• Library Functions: Predefined functions provided by C (e.g., ‘printf()‘, ‘strlen()‘).
• User-defined Functions: Functions created by the programmer for specific tasks.
4. Explain formal and actual arguments in function calls.
Answer:
• Actual arguments are the values passed to a function during a call.
• Formal arguments are the variables declared in the function definition that receive those
values.
Example:
void add ( int x , int y ) ; // x , y are formal arguments
add (5 , 10) ; // 5 , 10 are actual arguments
5. Differentiate between call by value and call by reference.
Answer:
• Call by Value: Copies the actual value into the function’s formal parameter. Changes do
not affect the original variable.
• Call by Reference: Passes the address of the variable. Changes inside the function affect
the original variable.
6. How are arrays passed to functions in C?
Answer:
Arrays are passed to functions by reference (i.e., the base address is passed). For 1-D arrays:
void display ( int arr [] , int size ) {
for ( int i = 0; i < size ; i ++)
printf ( " % d " , arr [ i ]) ;
}
For 2-D arrays, you must specify column size:
void printMatrix ( int mat [][3] , int rows ) {
// code to print matrix
}
7. What is a nested function? Does C support it?
Answer:
A nested function is a function defined inside another function. C does **not** support nested
functions in standard C. However, GNU C allows them as an extension.
8. What is recursion? Write a simple example.
Answer:
Recursion is a technique where a function calls itself to solve a smaller sub-problem.
Example: Factorial function
int factorial ( int n ) {
if ( n == 0) return 1;
else return n * factorial ( n - 1) ;
}
4. Interview Questions and Answers (UNIT 4)
1. What are storage classes in C? Explain their types.
Answer:
Storage classes define the scope, lifetime, and visibility of variables. Types include:
• auto: Default for local variables inside functions.
• register: Suggests storing variable in CPU register.
• static: Retains value across function calls.
• extern: Declares a global variable defined elsewhere.
2. What is a structure in C? What are its advantages?
Answer:
A structure is a user-defined data type that groups related variables of different data types.
Advantages:
• Organizes complex data logically.
• Easier data handling and manipulation.
• Useful for real-world modeling (e.g., student, book, employee).
3. How can you access elements of a structure?
Answer:
Use the dot (.) operator for direct access and arrow (-¿) operator for pointer access.
Example:
struct Student {
int roll ;
char name [20];
};
struct Student s1 ;
s1 . roll = 101; // Dot operator
struct Student * ptr = & s1 ;
ptr - > roll = 102; // Arrow operator
4. What is a nested structure in C?
Answer:
A nested structure means defining one structure inside another.
Example:
struct Date {
int day , month , year ;
};
struct Student {
char name [20];
struct Date dob ; // Nested structure
};
5. What is an array of structures? How is it useful?
Answer:
An array of structures stores multiple records of the same structure type.
Example:
struct Book {
int id ;
char title [30];
};
struct Book library [5]; // Array of 5 Book structures
6. How are functions used with structures?
Answer:
Structures can be:
• Passed to functions by value or reference.
• Returned from functions.
Example:
void display ( struct Student s ) {
printf ( " % d " , s . roll ) ;
}
7. Differentiate between structure and union. What is a bit-field?
Answer:
• Structure: All members have separate memory locations.
• Union: All members share the same memory location.
Bit-fields: Special structure members that occupy a specific number of bits.
Example:
struct Flags {
unsigned int a :1;
unsigned int b :1;
};
8. What is an enumerated data type in C?
Answer:
An enum defines a set of named integer constants.
Example:
enum Days { SUN , MON , TUE , WED };
enum Days d = MON ;
5. Interview Questions and Answers (UNIT 5)
1. What is a pointer in C and why is it used?
Answer:
A pointer is a variable that stores the memory address of another variable. Pointers are used
for:
• Efficient array and string handling
• Dynamic memory allocation
• Passing large structures to functions without copying
• Building complex data structures (linked lists, trees, etc.)
2. How do you declare and initialize a pointer in C?
Answer:
Syntax for declaring a pointer:
int * ptr ; // declares a pointer to an integer
Initialization example:
int a = 10;
int * ptr = & a ; // ptr stores the address of a
3. Explain the use of the * and & operators with pointers.
Answer:
• & (Address-of operator): Used to get the address of a variable.
• * (Dereference operator): Used to access the value at the address stored in a pointer.
Example:
int x = 20;
int * p = & x ;
printf ( " % d " , * p ) ; // prints 20
4. What are the different modes to open a file in C?
Answer:
File modes in C using fopen():
• "r" – Read (file must exist)
• "w" – Write (creates a new file or overwrites existing)
• "a" – Append (adds data to the end; creates file if not present)
• "r+" – Read and write (file must exist)
• "w+" – Read and write (creates or overwrites file)
• "a+" – Read and append (creates file if not present)
5. How do you read from and write to a file in C?
Answer:
To write to a file:
FILE * fp = fopen ( " output . txt " , " w " ) ;
fprintf ( fp , " Hello File ! " ) ;
fclose ( fp ) ;
To read from a file:
FILE * fp = fopen ( " output . txt " , " r " ) ;
char ch ;
while (( ch = fgetc ( fp ) ) != EOF )
printf ( " % c " , ch ) ;
fclose ( fp ) ;
6. What is the purpose of fscanf() and fprintf() in C?
Answer:
fprintf() is used to write formatted data to a file, and fscanf() is used to read formatted
input from a file.
Example:
FILE * fp = fopen ( " data . txt " , " w " ) ;
fprintf ( fp , " % d % s " , 101 , " Alice " ) ;
fclose ( fp ) ;
fp = fopen ( " data . txt " , " r " ) ;
int id ;
char name [20];
fscanf ( fp , " % d % s " , & id , name ) ;
fclose ( fp ) ;
7. Why should we always close a file after using it in C?
Answer:
Closing a file using fclose():
• Frees up system resources
• Ensures that all data is written properly to the file
• Prevents file corruption or data loss