Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

MAHARAJA INSTITUTE OF TECHNOLOGY MYSORE

DEPARTMENT OF COMPUTER SCIENCE &


ENGINEERING

Subject: Computer Programming Laboratory Subject Code: 18CPL17/27


Faculties: Honnaraju B
Academic Year: 2019-20
Viva Question Bank

1. What do you mean by Hardware and Software?


All the electronic/electrical components and circuits used in a computer system are called hardware. A
computer is actuated and controlled with the help of computer programs called software.

2. What is Algorithms?
An algorithm refers to the step by step instructions written to solve any problem.

3. What is Flowchart?
A flowchart is a diagrammatic or symbolic representation of algorithms. It uses various symbols to
represent the operations to be performed.

4. 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
double – a floating-point number, with more precision and perhaps greater range than float

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

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

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

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

9. What is preprocessor?

1 Honnaraju B, Dept. of CSE Maharaja Institute of Technology Mysore


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

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

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

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

14. What is identifier?


An identifier is a name used to identify a variable, function, symbolic constant and so on.

15. Mention the different types of operators used in C?


1. Arithmetic operator
2. Relational operators
3. Logical Operators
4. Increment and decrements operators
5. Assignment operators
6. Conditional operator
7. Bitwise operators
8. Special operator

16. What are 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
a. for loop
b. while loop
c. do – while loop

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

18. List a few unconditional control statement in C.


i. break statement

2 Honnaraju B, Dept. of CSE Maharaja Institute of Technology Mysore


ii. continue statement
iii. goto statement
iv. exit() function

19. What is an array?


An array is a collection of values of the same data type. Values in array are accessed using array
name with subscripts in brackets[]. Syntax of array declaration is
data type array_ name[size];

20. What is Multidimensional Arrays


An array with more than one index value is called a multidimensional array. To declare a
multidimensional array you can do follow syntax
data type array_ name[] [] []….;

21. Define string?


An array of characters is known as a string. for example
char st[8]; this statement declares a string array with 80 characters .

22. Mention four important string handling functions in C languages.


There are four important string handling functions in C languages.
i. strlen();
ii. strcpy();
iii. strcat();
iv. strcmp();
The header file #include is used when these functions are called in a C program.

23. Define and explain about ! Operator?


The logical operator ! NOT is a unary operator that is used before a single operand. It returns the
inverse value of the given operand so if the variable “c” had a value of true then! C would return value
of false. The not operator is very much useful in C programs because it can change the value of
variables with successful iterations. This ensures that on each pass the value is changed.

24. What is operator precedence?


Operator precedence defines the order in which C evaluates expressions.
e.g. in the expression a=6+b*3, the order of precedence determines whether the addition or the
multiplication is completed first. Operators on the same row have equal precedence.

25. Explain about the functions strcat() and strcmp()?


This function concatenates the source string at the end of the target string. strcmp() function
compares two strings to find out whether they are the same or different. The two strings are compared
character by character until there is a mismatch or end of one of the strings is reached, whichever occurs
first. If in case two strings are identical, a value of zero is returned. If there is no matches between two
strings then a difference of the two non- matching values are returned according to ASCII values.

26. Define function?


A function is a module or block of program code which deals with a particular task. Each
function has a name or identifier by which is used to refer to it in a program. A function can accept a
number of parameters or values which pass information from outside, and consists of a number of
statements and declarations, enclosed by curly braces { }, which make up the doing part of the object

27. Differentiate built-in functions and user – defined functions.

3 Honnaraju B, Dept. of CSE Maharaja Institute of Technology Mysore


Built – in functions are used to perform standard operations such as finding the square root of a
number, absolute value and so on. These are available along with the C compiler and are included in a
program using the header files math.h, string.h and so on.
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.
28. 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.

29. Explain the concept and use of type void.


A function which does not return a value directly to the calling program is referred as a void
function. The void functions are commonly used to perform a task and they can return many values
through global variable declaration.

30. What is recursion?


A function calling itself again and again to compute a value is referred to as recursive function or
recursion. Recursion is useful for branching processes and is effective where terms are generated
successively to compute a value.

31. How does the type float differ from double in C language?
Float data type refers real number in single precision and has 6 decimal digits. It takes 4 bytes in
memory to refer values ranging from 3.4e-38 to 3.4e+38
double data type also refers to real number but in double precision and has 12 decimal digits. It
takes 8 bytes of memory to refer values ranging from 1.7e-308 to 1.7e+308

32. What is an operator and operand?


An operator performs an operation like addition, subtraction and so on and produces a value.
Variables and constants upon which operations are performed are called operands.

33. What is RAM?


RAM – Random Access Memory is a temporary storage medium in a computer. RAM is a
volatile memory i.e all data stored in RAM will be erased when the computer is switched off.

34. What is ROM?


ROM – Read Only Memory is permanent storage medium which stores start up programs
(operating system programs) and BIOS programs which are recorded by the manufacturer of the
compiler system. ROM is a non-volatile memory.

35. Define system software.


System software is a collection of programs which are used to assist the user to handle the
computer hardware like printer, disk and so on and execute the application programs.

36. Define application software


Application software are programs which are used to solve specific problems /tasks. Examples
include railway reservation, banking and so on.

37. What are control statements?


All the statements written in a program are executed from top to bottom one by one. Control
statements are used to execute / transfer the control from one part of the program to another depending
on conditions.

4 Honnaraju B, Dept. of CSE Maharaja Institute of Technology Mysore


38. Explain increment and decrements operators.
++ increment operator which add one to the value,
example : i++ (which adds one to i and results is scored back to)
-- decrement operator which subtracts one from the value
Example -- i ( which subtracts one from i)

39. Mention the types of memory.


Two major types of memory storage is primary memory and secondary memory. Primary
storage (or main memory or internal memory), often referred to simply as memory, is the only one
directly accessible to the CPU.
Secondary memory (or external memory) differs from primary storage in that it is not directly
accessible by the CPU. Some of the example for secondary memory includes floppy disks, flash
memory, magnetic tape, hard drives etc.

40. What are input and output device?


Input and Output Devices: Input devices are the hardware that are used for providing information
to the computer like mouse and keyboard and output devices are the hardware that are used for receiving
information from computer like monitor, printer or the sound system.

41. What is a compiler?


Compile is a software program that transfer program developed in high level language into executable object code

42. What is a program?


A computer program is a collection of the instructions necessary to solve a specific problem.

43. What is a header file?


Header files provide the definitions and declarations for the library functions. Thus, each header
file contains the library functions along with the necessary definitions and declarations. For example,
stdio.h, math.h, stdlib.h, string.h etc.

44. What is character set?


Character set is the set of characters allowed and supported in the programming language.
Generally a program is a collection of instructions, which contain groups of characters. Only a limited
set of characters is allowed to write instructions in the program.

45. What is C token?


The smallest individual units of a C program are known as tokens.

46. What are the rules for the identifier?


The first character must be an alphabet or underscore (_) Digits may be included in the variable.
The maximum number of characters in a word are 32 (It may vary depending upon the platform) No
other special characters are allowed.

47. What is a keyword?


Keywords are those words of C which have predefined meaning assigned by the C language.
They form a part of the database required by the C compiler.

48. Give the rules for variable declaration?


The rules for variable declaration in C are given below:
 A variable name consists of alphabets, digits and the underscore (_) character

5 Honnaraju B, Dept. of CSE Maharaja Institute of Technology Mysore


 The length of variable should be kept upto 8 characters though your system may allow upto 40
characters
 They must begin with an alphabet
 Some systems also recognize an underscore as the first character
 White space and commas are not allowed
 Any reserved word (keyword) cannot be used as a variable name.

49. What is the use of a „\0‟ character?


It is referred to as a terminating null character, and is used primarily to show the end of a string
value.

50. What is the difference between the = symbol and == symbol?


The = symbol is often used in mathematical operations. It is used to assign a value to a given
variable. On the other hand, the == symbol, also known as “equal to” or “equivalent to”, is a relational
operator that is used to compare two values.

51. What is the modulus operator?


The modulus operator outputs the remainder of a division. It makes use of the percentage (%)
symbol. For example: 10 % 3 = 1, meaning when you divide 10 by 3, the remainder is 1.

52. What is a nested loop?


A nested loop is a loop that runs within another loop. Put it in another sense, you have an inner
loop that is inside an outer loop. In this scenario, the inner loop is performed a number of times as
specified by the outer loop. For each turn on the outer loop, the inner loop is first performed.

53. Which of the following operators is incorrect and why?


( >=, <=, <>, ==)
<> is incorrect. While this operator is correctly interpreted as “not equal to” in writing conditional
statements, it is not the proper operator to be used in C programming. Instead, the operator != must be
used to indicate “not equal to” condition.

54. Compare and contrast compilers from interpreters.


Compilers and interpreters often deal with how program codes are executed. Interpreters execute
program codes one line at a time, while compilers take the program as a whole and convert it into object
code, before executing it. The key difference here is that in the case of interpreters, a program may
encounter syntax errors in the middle of execution, and will stop from there. On the other hand,
compilers check the syntax of the entire program and will only proceed to execution when no syntax
errors are found.

55. Not all reserved words are written in lowercase. TRUE or FALSE?
FALSE. All reserved words must be written in lowercase; otherwise the C compiler would
interpret this as unidentified and invalid.

56. What is the difference between the expression “++a” and “a++”?
In the first expression, the increment would happen first on variable a, and the resulting value will be the
one to be used. This is also known as a prefix increment. In the second expression, the current value of
variable a would the one to be used in an operation, before the value of a itself is incremented. This is
also known as postfix increment.

57. When is a “switch” statement preferable over an “if” statement?


The switch statement is best used when dealing with selections based on a single variable or
expression. However, switch statements can only evaluate integer and character data types.

6 Honnaraju B, Dept. of CSE Maharaja Institute of Technology Mysore


58. What are global variables and how do you declare them?
Global variables are variables that can be accessed and manipulated anywhere in the program.
To make a variable global, place the variable declaration on the upper portion of the program, just after
the preprocessor directives section.

59. What are enumerated types?


Enumerated types allow the programmer to use more meaningful words as values to a variable.
Each item in the enumerated type variable is actually associated with a numeric code. For example, one
can create an enumerated type variable named DAYS whose values are Monday, Tuesday… Sunday.

60. What does the function toupper() do?


It is used to convert any letter to its upper case mode. toupper() function prototype is declared in
<ctype.h>. Note that this function will only convert a single character, and not an entire string.

61. Is it possible to have a function as a parameter in another function?


Yes, that is allowed in C programming. You just need to include the entire function prototype
into the parameter field of the other function where it is to be used.

62. What are multidimensional arrays?


Multidimensional arrays are capable of storing data in a two or more dimensional structure. For
example, you can use a 2 dimensional array to store the current position of pieces in a chess game, or
position of players in a tic-tac-toe program.

63. What are pointers?


Pointers point to specific areas in the memory. Pointers contain the address of a variable, which in turn
may contain a value or even an address to another memory.

64. Can you pass an entire structure to functions?


Yes, it is possible to pass an entire structure to a function in a call by method style. However,
some programmers prefer declaring the structure globally, then pass a variable of that structure type to a
function. This method helps maintain consistency and uniformity in terms of argument type.

65. What are the uses of a pointer?


Pointer is used in the following cases
i) It is used to access array elements
ii) It is used for dynamic memory allocation.
iii) It is used in Call by reference
iv) It is used in data structures like trees, graph, linked list etc.

66. What is a structure?


Structure constitutes a super data type which represents several different data types in a single unit.
A structure can be initialized if it is static or global.

68. What is a union?


Union is a collection of heterogeneous data type but it uses efficient memory utilization technique
by allocating enough memory to hold the largest member. Here a single area of memory contains values
of different types at different time. A union can never be initialized.

69. What are the differences between structures and union?

7 Honnaraju B, Dept. of CSE Maharaja Institute of Technology Mysore


A structure variable contains each of the named members, and its size is large enough to hold all
the members. Structure elements are of same size. A union contains one of the named members at a
given time and is large enough to hold the largest member. Union element can be of different sizes.

70. What are macros? What are its advantages and disadvantages?
Macros are abbreviations for lengthy and frequently used statements. When a macro is called the
entire code is substituted by a single line though the macro definition is of several lines. The advantage
of macro is that it reduces the time taken for control transfer as in case of function. The disadvantage of
it is here the entire code is substituted so the program becomes lengthy if a macro is called several times.

71. Difference between pass by reference and pass by value?


Pass by reference passes a pointer to the value. This allows the callee to modify the variable
directly. Pass by value gives a copy of the value to the callee. This allows the callee to modify the value
without modifying the variable. (In other words, the callee simply cannot modify the variable, since it
lacks a reference to it.)

72. What is the use of typedef?


The typedef help in easier modification when the programs are ported to another machine. A
descriptive new name given to the existing data type may be easier to understand the code.

73. What is a linear search?


A linear search refers to the way a target key is being searched in a sequential data structure.
Using this method, each element in the list is checked and compared against the target key, and is
repeated until found or if the end of the list has been reached.

74. What is a macro, and how do you use it?


A macro is a preprocessor directive that provides a mechanism for token replacement in your
source code. Macros are created by using the #define statement. Here is an example of a macro:
#define VERSION_STAMP "1.02"

78. What is the difference between #include and #include "file"?


When writing your C program, you can include files in two ways. The first way is to surround
the file you want to include with the angled brackets < and >. This method of inclusion tells the
preprocessor to look for the file in the predefined default location. This predefined default location is
often an INCLUDE environment variable that denotes the path to your include files.

8 Honnaraju B, Dept. of CSE Maharaja Institute of Technology Mysore

You might also like