CPL Question Bank (Viva)
CPL Question Bank (Viva)
Viva Questions
Question Bank
8) What is C Language?
Solution: C is a high level language in which high language represents English written
instructions.
Solution: In C, the "main" function is treated the same as every function, it has a return
type (and in some cases accepts inputs via parameters). The only difference is that the
main function is "called" by the operating system when the user runs the program.
12) What is data type?
Solution : A data type is a type of data. Some common data types include integers, floating point
numbers, characters, strings, and arrays.
Solution: The printf() is a library function to send formatted output to the screen. The
function prints the string inside quotations. To use printf() in our program, we need to
include stdio. h header file using the #include <stdio.h>
Solution : The scanf function allows you to accept input from standard in, which for us is
generally the keyboard. ... scanf("%d", &b); The program will read in an integer value
that the user enters on the keyboard (%d is for integers, as is printf, so b must be declared
as an int) and place that value into b.
Solution: The format specifiers are used in C for input and output purposes. Using this
concept the compiler can understand that what type of data is in a variable during taking
input using the scanf() function and printing using printf() function.
Example :%d- integer,%f-floating point ,%c-character
20)What is Switch statement ?
Solution : A switch statement allows a variable to be tested for equality against a list of
values. Each value is called a case, and the variable being switched on is checked for
each switch case.
Solution: When a break statement is reached, the switch terminates, and the flow of
control jumps to the next line following the switch statement. The break statement
is optional. If omitted, execution will continue on into the next case. The flow of
control will fall through to subsequent cases until a break is reached.
If the Boolean expression evaluates to true, then the block of code inside the
'if' statement will be executed. If the Boolean expression evaluates to false, then the first
set of code after the end of the 'if' statement (after the closing curly brace) will be
executed.
23) Difference between if and switch statements?
Solution:
SWITCH allows expression to have integer based evaluation while IF statement allows both
integer and character based evaluation. 5. SWITCH statement can be executed with all
cases if the 'break' statement is not used whereas IF statement has to be true to be executed
further.
24) What is quadratic Equation and math.h function?
Solution:
The solutions of the quadratic equation ax2 + bx + c = 0 correspond to the roots of the
function f(x) = ax2 + bx + c, since they are the values of x for which f(x) = 0.
The math.h header defines various mathematical functions and one macro Ex: fabs,sqrt
Solution: With loop control statements, you can repeatedly execute a block of code.
Solution: he difference is that the do while loop executes at least once because it checks for
the loop condition while exiting. While is a entry controlled loop and do while is a exit
control loop. Whereas in do while loop it will enter the loop and will then check for the
condition.
27. What is for loop ?
Solution : A for loop is a repetition control structure that allows you to efficiently write a loop that needs to
execute a specific number of times.
Syntax
The syntax of a for loop in C programming language is −
for ( init; condition; increment ) {
statement(s);
}
Solution: The conditional expressions are evaluated from the top downward. As soon as a true
condition is found, the statement associated with it is executed, and the rest of the ladder is
bypassed. If none of the conditions is true, then the final else statement will be executed.
Solution: Conditional Statements in C programming are used to make decisions based on the
conditions. Conditional statements execute sequentially when there is no condition around
the statements. ... It is also called as branching as a program decides which statement to
execute based on the result of the evaluated condition.
Solution: Linear search is a very simple search algorithm. In this type of search, a sequential
search is made over all items one by one. Every item is checked and if a match is found then that
particular item is returned, otherwise the search continues till the end of the data collection.
Solution: Binary search looks for a particular item by comparing the middle most item of the
collection. If a match occurs, then the index of item is returned. If the middle item is greater than
the item, then the item is searched in the sub-array to the left of the middle item. Otherwise, the
item is searched for in the sub-array to the right of the middle item. This process continues on the
sub-array as well until the size of the subarray reduces to zero.
User-defined functions
Solution: Multidimensional arrays are an extension of 2-D matrices and use additional
subscripts for indexing. A 3-D array, for example, uses three subscripts. The first two are just
like a matrix, but the third dimension represents pages or sheets of elements.
Solution: n a two dimensional array like int[][] numbers = new int[3][2], there are three rows
and two columns. You can also visualize it like 3 integer array of length 2. You can find the
number of rows using numbers.
Solution: The preprocessor directives give instruction to the compiler to preprocess the
information before actual compilation starts. ... C# compiler does not have a
separate preprocessor; however, the directives are processed as if there was one. In C#
the preprocessor directives are used to help in conditional compilation.
Solution: Strings are actually one-dimensional array of characters terminated by a null character
'\0'. Thus a null-terminated string contains the characters that comprise the string followed by
a null.
Solution : Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm
that repeatedly steps through the list, compares adjacent elements and swaps them if they are
in the wrong order. The pass through the list is repeated until the list is sorted.
41. What is nested for loop?
Solution : C programming allows to use one loop inside another loop. The following section
shows a few examples to illustrate the concept.
Syntax
The syntax for a nested for loop statement in C is as follows −
for ( init; condition; increment ) {
Solution : Typecasting, or type conversion, is a method of changing an entity from one data
type to another. ... An example of typecasting is converting an integer to a string. This might
be done in order to compare two numbers, when one number is saved as a string and the other
is an integer.
Solution : A structure is a user defined data type in C/C++. A structure creates a data type that
can be used to group items of possibly different types into a single type.
struct address
{
char name[50];
char street[100];
char city[50];
char state[20];
int pin;
};
int main()
{
struct Point p1; // The variable p1 is declared like a normal variable
}
Solution: A pointer is nothing but a memory location where data is stored. A pointer is used to
access the memory location. There are various types of pointers such as a null pointer,
wild pointer, void pointer and other types of pointers. Pointers can be used with array and
string to access elements more efficiently.
//Pointer declaration
int *p;