CP_Viva_Questions_First_Year_Engineering_v3
CP_Viva_Questions_First_Year_Engineering_v3
1. Introduction to Programming
Q: What is a computer program?
A: A programming language provides a formal way for humans to write instructions that a computer
A: In compiled languages, the source code is translated into machine code all at once by a compiler
before execution. In interpreted languages, the source code is translated and executed line by line
by an interpreter.
declarations (optional), main() function: where the program starts execution, Code for operations
A: Data types define the type of data a variable can store, such as integers, floating-point numbers,
A: `int` is used to store integer values (whole numbers), while `float` is used to store decimal
A: A variable is a name given to a memory location where data can be stored and manipulated
during the execution of a program.
A: The `const` keyword is used to define constants, which are variables whose values cannot be
3. Operators
Q: What is an operator in programming?
A: An operator is a symbol that tells the compiler to perform specific mathematical or logical
A: `=` is the assignment operator, used to assign a value to a variable, while `==` is the equality
A: Arithmetic operators are used to perform mathematical operations, such as: `+` (addition), `-`
A: Relational operators are used to compare two values, such as: `==` (equal to), `!=` (not equal to),
`>` (greater than), `<` (less than), `>=` (greater than or equal to), `<=` (less than or equal to).
A: Control flow statements allow the program to decide which path to take based on conditions.
These include conditional statements (`if`, `else`) and loop statements (`for`, `while`, `do-while`).
A: The `if-else` statement allows the program to execute one block of code if a condition is true and
A: The `break` statement is used to exit from a loop or a switch statement prematurely.
A: The `switch` statement is a control flow statement that allows multi-way branching. It evaluates an
expression and matches it with case values to execute the corresponding code block.
5. Functions
Q: What is a function in C programming?
A: A function is a block of code that performs a specific task. It can take input values (parameters),
A: The `return` statement is used to exit from a function and return a value to the calling function. It
A: A function declaration declares the function's signature, telling the compiler the function's name,
return type, and parameters. A function definition includes the actual implementation of the function.
A: A recursive function is a function that calls itself in order to solve a smaller version of the same
6. Arrays
Q: What is an array in C?
A: An array is a collection of elements of the same data type, stored in contiguous memory
A: Elements of an array are accessed using an index. For example, to access the first element:
`arr[0]`.
A: A one-dimensional array stores elements in a single line, while a two-dimensional array stores
7. Strings
Q: What is a string in C?
characters.
A: A string is declared like an array of characters. For example: `char str[] = "Hello";`
A: The `strlen()` function is used to find the length of a string, excluding the null character.
A: The `strcpy()` function is used to copy one string into another. It takes two arguments: the
8. Pointers
Q: What is a pointer in C?
A: A pointer is a variable that stores the memory address of another variable. It allows indirect
A: A pointer is declared by placing an asterisk (`*`) before the pointer variable, like so: `int *ptr;`
Q: What is the purpose of the `&` operator?
A: The `&` operator is used to get the memory address of a variable. For example, `&var` gives the
address of `var`.
A: An array is a collection of elements stored in contiguous memory locations, while a pointer stores
9. File Handling
Q: What is file handling in C?
A: File handling in C allows programs to read from and write to files on disk. It uses file pointers to
A: Common file operations include opening files (`fopen()`), reading files (`fscanf()`, `fgetc()`), writing
A: The `fopen()` function is used to open a file in a specified mode (read, write, append). It returns a
file pointer.
A: The `fclose()` function is used to close a file that was opened using `fopen()`.