C Viva Questions
C Viva Questions
C Viva Questions
1
16. How to declare a variable?
a. The syntax for declaring variable is
b. data type variable_name-1, variable_name-2,....variable_name-n;
17. What is meant by initialization and how we initialize a variable?
a. While declaring a variable assigning value is known as initialization. Variable can
be initialized by using assignment operator (=).
18. What are integer variable, floating-point variable and character variable?
a. A variable which stores integer constants are called integer variable. A variable
which stores real values are called floating-point variable. A variable which stores
character constants are called character variables.
19. How many types of operator or there in C?
a. C consist Arithmetic Operators (+, -, *, /,%), Relational Operators (<, <=, >, >=,
!=), Logical Operators (&&, ||, !), Assignment Operators (=, +=, -=, *=, /=),
Increment and Decrement Operators (++, --), Conditional Operator(?:), Bitwise
Operators(<<, >>, ~, &, |, ^) and Special Operators (. , ->, &, *, sizeof)
20. What is a Unary operator and what are the unary operators present in C?
a. An operator which takes only one operand is called unary operator. C unary
operators are
b. Unary plus (+), Unary minus (-), Increment and Decrement operators (++,--),
Address of operator (&), Value at operator (*), sizeof operator, ones complement
operator (~).
21. What is a ternary operator and which is called ternary operator is C?
a. An operator which takes three operands is called ternary operator. Conditional
operator (? :) is knows as ternary operator in C.
22. What is the use of modulus (%) operator?
a. The modulus operator produces the remainder of an integer division. It cannot be
used on floating point data.
23. What is the use of printf and scanf functions in C?
a. Values of variables and results of expressions can be displayed on the screen
using printf functions. Values to variables can be accepted through the keyboard
using scanf function.
24. What are the format codes used in printf and scanf functions in C?
a. %c (for reading or printing a single character), %d (for reading or printing signed
integer), %u (for reading or printing unsigned integer), %ld (for reading or
printing long signed integer), %lu (for reading or printing long unsigned integer),
%f (for reading or printing floating point value), %lf (for reading or printing
double floating point value), %Lf (for reading or printing long double value, %s
(for reading or printing string value)
25. What are the decision making statements available in C?
a. IF statement, Switch statement and conditional statement
26. What is the use of IF statement and how it works?
a. The IF statement is used to control the flow of execution of statements. It first
evaluates the given expression and then, depending on whether the value of the
expression is true or false, it transfers the control to a particular statement.
2
27. Forms of IF statements?
a. Simple IF statement, IF-ELSE statement, NESTED IF-ELSE statement and ELSE
IF ladder
28. How switch statement works?
a. The switch statement tests the value of a given variable against a list of case
values and when a match is found, block of statement associated with that case is
executed and if no match is found then the block of statements associated with the
optional default is executed. If default case not present, control goes to the
statement after the switch.
29. What is the difference between IF and SWITCH statement?
a. IF works on integers, floats and characters whereas SWITCH works on only
integers and characters. Switch statement cannot perform inequality comparisons
whereas IF can perform both equality and inequality comparisons.
30. How conditional operator (? :) works?
a. The conditional expression is evaluated first. If the expression is true then
expression after the question mark is executed otherwise expression after the
colon is executed
31. What is GOTO statement?
a. GOTO is an unconditional branching statement which transfer control to the
specified label
32. What is a LOOP?
a. Loop is a sequence of statements that are executed repeatedly
33. What are the types of LOOP control statement?
a. Entry-Controlled Loop statement and Exit-Controlled loop statement
34. What are the LOOP control statements present in C?
a. WHILE, DO-WHILE, FOR
35. What are the sections present in FOR loop?
a. Initialization section, Conditional section, increment or decrement section
36. How a FOR loop works?
a. In FOR loop first initialization section is executed, then given condition is
checked. If condition becomes true then body of the loop is executed after that
increment or decrement section is executed
37. What is the use of break statement?
a. Break statement is used to exit from a loop
38. What is an ARRAY?
a. Array is a collective name given to similar elements
39. How ARRAY elements are stored in memory?
a. Array elements are stored in consecutive memory locations
40. How we can initialize an ARRAY?
a. All the element are separated by comma and enclosed within braces
41. How to access array element?
a. Array elements can be accessed by using subscript
42. What is the difference between normal variable and array variable?
a. A variable can store only one value at a time whereas array variable can store
several value at a time.
3
43. What are the types of Array’s?
a. One-Dimensional array, Two-Dimensional array and Multi-Dimensional array
44. What is a TWO-DIMENSIONAL array?
a. A Two-Dimensional array is an array which has elements as one-dimensional
arrays?
45. What is a character array?
a. Array which can store several characters is called character array
46. How to initialize a character array?
a. Character arrays can be initialized by separating character constants with comma
and enclosed with in parenthesis or characters enclosed within double quotation
marks.
47. What is the difference between reading strings using scanf and gets?
a. Scanf can not read strings with multiple words whereas gets can read strings with
multiple words
48. What are the String-Handling functions available in C?
a. gets, puts, strcat, strcmp, strcpy and strlen.
49. What are the types of functions?
a. C functions are divided into two categories user-defined function and built-in
functions
50. What is a function?
a. Function is a self contained block of statement which is used to perform certain
task
51. Which are called built-in functions?
a. Printf, scanf, clrscr, gotoxy, string handling functions and file handling functions
52. What is function prototype declaration?
a. A function declaration is also known as function prototype declaration which
contains function return type, function name, parameter list and terminating
semicolon
53. What are formal arguments and actual arguments?
a. Arguments that are used in function calling are called actual arguments.
Arguments that are used in function definition are called formal arguments
54. What is a recursive function?
a. A function calling itself is called function recursion
55. What is call by value and call by reference?
a. Passing values to the called function is called call by value, passing addresses to
the called function is called call by reference
56. How to pass an array to a function?
a. Arrays are passed to a function by sending its address
57. What is a global variable and local variable?
a. Variables which are declared in the global section is called global variables and
Variables which are declared in a function or a block are called local variables
58. What is a pointer variable?
a. Pointer variable is a variable which can store address of another variable
59. How can we store address of a variable in a pointer?
a. By using address of operator we can store address of a variable in a pointer
60. How can we access a variable value using a pointer?
4
a. By using value at operator we can access a variable value using its pointer
61. What is the use of pointers?
a. Pointer are used to pass array and structures from function to another function
62. How many bytes a pointer variable occupies in memory?
a. A pointer variable irrespective of its type it occupies two bytes in memory
63. What are the storage classes available in C?
a. Auto, Static, Extern and Register
64. What is a structure?
a. Structure is a user-defined data type. Structure is a collective name given to
dissimilar elements
65. How to access structure members?
a. Structure members can be accessed using dot operator
66. How to initialize structure variable?
a. All the members are separated by comma and are enclosed within braces
67. What are the differences between structures and arrays?
a. Structures stores dissimilar values where as arrays stores similar values. One
structure variable can assigned to another structure variable whereas one array
variable cannot be assigned to another array variable
68. What is the size of a structure?
a. Sum of all the members size is becomes structure size
69. How to access structure member by its pointer?
a. We can use structure members using arrow operator with its pointer
70. What is a union?
a. Union is a user-defined data type which can store a value of different data types
71. What is the difference between structures and unions?
a. Structures can store several values at a time whereas unions can store one value at
a time. A structure size becomes sum of all its members whereas a union size
becomes size of a member whose size is largest
72. What are the types of files we can create using C?
a. We can create text and binary files using C
73. What are the file-handling functions present in C?
a. fopen, fclose, fgetc, fputc, fgets, fputs, fprintf, fscanf, fread, fwrite, fseek
74. What are the file opening modes present in C?
a. r, w, a, r+, w+, a+, rb, wb, rb+, wb+
1. What is Algorithms?
An algorithms refer to the step by step instructions written to solve any problem.
2. What is Flowchart ?
A flowchart is a diagrammatic or symbolic representation of an algorithms. It uses various
symbols to represent the operations to be performed.
3. Name the four basic data types in “C” language?
The four basic data types in “c” language are as follows
char – a character
int – an integer, in the range -32,767 to 32,767
long int – a larger integer (up to +-2,147,483,647)
float – a floating-point number
5
double – a floating-point number, with more precision and perhaps greater range than float
4. Describe at least five different format specifiers?
%d: -An integer whole number
%f: -a floating point number
%c: -a single character
%s: -a string of value of characters.
5. Define and explain scanf () function?
The Scanf () function can be used to get input into a program and it requires two arguments.
First a format specifier defines the type of data to be entered, then the name of the variable in
which the input will be stored. This scanf () function is responsible for giving input into the
program.
6. Define and explain printf () function?
The printf() function is used to display/output values of variable in the monitor. The printf
function has general form: printf (“format specifiers”,variables)
7. What are the maximum and minimum possible ranges of values for long and short
type?
If the int variable is created by default as a ‘long’ type it typically will have a possible range
of values from a maximum of +214748347 and a minimum of -2147483648. For ‘short’ type
these are the maximum and minimum values +327676 and minimum -32768.
(While answering this question you can specify the approximate value raised to power).
8. What is preprocessor?
The preprocessor is a program which is executed before the compilation of a source program
written by the user. The preprocessor directives begines with hash (#) followed by the
command. e.g #include – it is a directive to include file.
9. What exactly is a ‘variable scope’, ‘local variables’ and ‘global variables’?
The extent to which a variable is accessible in a program is called the ‘variable scope’.
Variables declared internally inside a function are known as ‘local’ variables.
Variables declared externally outside a function are known as ‘global’ variables.
10. What are signed values?
When an int variable is declared it can by default contain either positive of negative integer
values. These are known as ‘signed’ values. The range of positive values is determined by
your system.
11. Define reserved words.
C programs are constructed from a set of reserved words which provide control and from
libraries which perform special functions. The basic instructions are built up using a reserved
set of words, such as main, for, if,while, default, double, extern, for, and int, to name just a
few.
12. What is the purpose of type declaration in C ?
All variables used in a C program are declared using the appropriate data types to enable the
compiler to allocate the required number by bytes in RAM to store values of these variables
in memory
13. What is identifier ?
An identifier is a name used to identify a variable, function, symbolic constsnt and so on.
14. Mention the different types of operators used in C ?
Arithmetic operator
6
Relational operators
Logical Operators
Increment and decrements operators
Assignment operators
Conditional operator
Bitwise oprators
15. What is Loop control statements ?
Loop control structures are used to execute and repeat a block of statements depending on the
value of a condition. There are 3 types of loop control statements in C
for loop
while loop
do – while loop
16. explain while loop .
A while loop has one control expression, and executes as long as that expression is true. The
general syntax of a while loop is
while( expression ){
statements
}
we use a while loop when a statement or group of statements which may have to be executed
a number of times to complete their task. The controlling expression represents the condition
17. explain for loop .
A for loop is used to execute and repeat a block of statements depending on a condition. The
syntax of a for loop is
for(initilaisation;condition;update )
{
Statements;
}
7
char st[8]; this statement declares a string array with 80 characters .
8
User defined functions are written by the user or programmer to compute a value or perform
a task. It contains a statement block which is executed during the runtime whenever it is
called by the main program.
30. Distinguish between actual and formal arguments.
Actual arguments are variables whose values are supplied to the function in any function call.
Formal arguments are variables used to receive the values of actual arguments from the
calling program.