0% found this document useful (0 votes)
7 views

CP_Viva_Questions_First_Year_Engineering_v3

Cp

Uploaded by

jaythakare254
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

CP_Viva_Questions_First_Year_Engineering_v3

Cp

Uploaded by

jaythakare254
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Oral Viva Questions on Computer Programming (CP) - First Year Engineerin

1. Introduction to Programming
Q: What is a computer program?

A: A computer program is a set of instructions written in a programming language to perform a

specific task or solve a problem.

Q: What is the role of a programming language?

A: A programming language provides a formal way for humans to write instructions that a computer

can understand and execute.

Q: What is the difference between compiled and interpreted languages?

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.

Q: What is the structure of a basic C program?

A: A basic C program structure includes: Preprocessor directives (#include), Global variable

declarations (optional), main() function: where the program starts execution, Code for operations

and return statements.

2. Data Types and Variables


Q: What are data types?

A: Data types define the type of data a variable can store, such as integers, floating-point numbers,

characters, and booleans.

Q: What is the difference between `int` and `float` in C?

A: `int` is used to store integer values (whole numbers), while `float` is used to store decimal

numbers (real numbers).

Q: What are variables?

A: A variable is a name given to a memory location where data can be stored and manipulated
during the execution of a program.

Q: What is the purpose of the `const` keyword?

A: The `const` keyword is used to define constants, which are variables whose values cannot be

changed during the execution of the program.

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

operations on variables or values.

Q: What is the difference between `=` and `==` in C?

A: `=` is the assignment operator, used to assign a value to a variable, while `==` is the equality

operator, used to compare two values for equality.

Q: What are arithmetic operators?

A: Arithmetic operators are used to perform mathematical operations, such as: `+` (addition), `-`

(subtraction), `*` (multiplication), `/` (division), `%` (modulus).

Q: What are relational operators?

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).

4. Control Flow Statements


Q: What are control flow statements?

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`).

Q: Explain the `if-else` statement.

A: The `if-else` statement allows the program to execute one block of code if a condition is true and

another block if the condition is false.

Q: What is a `for` loop?


A: A `for` loop is used to execute a block of code repeatedly for a specific number of iterations. The

syntax is: `for (initialization; condition; increment/decrement)`.

Q: What is the `break` statement used for?

A: The `break` statement is used to exit from a loop or a switch statement prematurely.

Q: What is a `switch` statement?

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),

perform operations, and return a result.

Q: What is the purpose of the `return` statement?

A: The `return` statement is used to exit from a function and return a value to the calling function. It

also terminates the execution of the function.

Q: What is the difference between a function declaration and a function definition?

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.

Q: What is a recursive function?

A: A recursive function is a function that calls itself in order to solve a smaller version of the same

problem. The base case is crucial to stop the recursion.

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

locations. The elements are accessed using an index.

Q: How do you declare an array in C?


A: An array is declared by specifying the data type, followed by the array name, and the size of the

array, like so: `int arr[5];`

Q: How do you access elements of an array?

A: Elements of an array are accessed using an index. For example, to access the first element:

`arr[0]`.

Q: What is the difference between a one-dimensional array and a two-dimensional array?

A: A one-dimensional array stores elements in a single line, while a two-dimensional array stores

elements in a matrix format (rows and columns).

7. Strings
Q: What is a string in C?

A: A string in C is a sequence of characters terminated by a null character `\0`. It is an array of

characters.

Q: How do you declare and initialize a string in C?

A: A string is declared like an array of characters. For example: `char str[] = "Hello";`

Q: What is the `strlen()` function?

A: The `strlen()` function is used to find the length of a string, excluding the null character.

Q: What is the `strcpy()` function?

A: The `strcpy()` function is used to copy one string into another. It takes two arguments: the

destination string and the source string.

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

access to the variable's value.

Q: How do you declare a pointer?

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`.

Q: What is the difference between a pointer and an array in C?

A: An array is a collection of elements stored in contiguous memory locations, while a pointer stores

the memory address of a variable or an element in an array.

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

interact with files.

Q: What are the common file operations in C?

A: Common file operations include opening files (`fopen()`), reading files (`fscanf()`, `fgetc()`), writing

to files (`fprintf()`, `fputc()`), and closing files (`fclose()`).

Q: What is the `fopen()` function?

A: The `fopen()` function is used to open a file in a specified mode (read, write, append). It returns a

file pointer.

Q: How do you close a file in C?

A: The `fclose()` function is used to close a file that was opened using `fopen()`.

You might also like