Computer Programming Viva Questions


1) What is C language?
C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972.
The C programming language is a standardized programming language developed in the
early 1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating
It has since spread to many other operating systems, and is one of the most widely used
programming languages.

2) What is an algorithm?
Ans: An algorithm is a step-by-step method of performing any task.

3) What is a flow chart?
Ans: A flowchart is a type of diagram that represents an algorithm or process, showing
the steps as boxes of various kinds, and their order by connecting these with arrows.

4) What is a C Preprocessor?
Ans: C Preprocessor is a program that processes our source program before it is passed to
the compiler.

5) What is the use of header files as used in C programming?
Ans: Header files are used to have declarations. It is simple to include a single header file
than writing allthe needed functions prototypes.

6) What is the Structure of a C Program?
Ans: Documentation Section, Linking Section, Definition Section, Global declaration
Section, main function, subprogram section.

7) Explain some Header Files?
S.No Description
This is standard input/output header file in
1 stdio.h which Input/Output
functions are declared
2 conio.h This is console input/output header file
All string related functions are defined in this
3 string.h
header file
This header file contains general functions
4 stdlib.h
used in C programs

Prepared By: P. HARI SHANKAR

often having a binary form known as object code). float. (or) the basic element recognized by the compiler is the "token. string. • printf() function is used to print the “character. Punctuators 14) What are Printf() and scanf() Functions : Ans: printf() and scanf() functions are inbuilt library functions in C which are available in which are available in “ stdio. HARI SHANKAR . String – literal. 11) What is a Translator? Ans: A translator is a computer program that translates a program written in a given programming language into a functionally equivalent program in a different language." C Tokens are: Key Words. 9) What are the types of constants in c? Ans: C constants can ba divided into two categories: 1) Primary constants (Numerical) 2) Secondary constants (Character) 10) What is a Compiler? Ans: A compiler is a computer program (or set of programs) that transforms source code written in a programming language (the source language) into another computer language (the target language. Operator.h header file 8) What is the use of main() function? Ans: main() is the starting point of program execution.Computer Programming Viva Questions All maths related functions are defined in this 5 math. 13) What is a Token in C? Ans: A Token is the basic building block of a C.h” header file.e. octal and hexadecimal values” onto the output screen. performs. numeric data from keyboard Prepared By: P. 12) What is a Interpreter? Ans: An Interpreter is a computer program that directly executes. instructions written in a programming or scripting language. Constants. Identifier. integer. without previously batch- compiling them into machine language. i. string. • scanf() function is used to read character.

List of Data Types: 1) Basic Data Types: Int.647. • int (2 byte) can store values from -32.147.147. long int 2) Enumeration Data Type: enum 3) Derived Data Type: Pointer.767 8 unsigned short int 2 0 to 65.535 9 signed short int 2 –32.647 12 unsigned long int 4 0 to 4.483.147.647 to 2.767 to 32.483. array.648 to +2.768 to +32.767 10 long long int 8 –(2power(63) –1) to 2(power)63 –1 11 signed long int 4 –2. union 4) Void Data Type: void 16) What is Integer Data Type? Ans: Integer data type allows a variable to store numeric values.647 7 short int 2 –32. storage S.147.No C Data types Range Size 1 char 1 –127 to 127 2 int 2 –32.767 1E–37 to 1E+37 with six digits of 3 float 4 precision 1E–37 to 1E+37 with ten digits of 4 double 8 precision 1E–37 to 1E+37 with ten digits of 5 long double 10 precision 6 long int 4 –2.483. Double.767 to 32. HARI SHANKAR .Computer Programming Viva Questions 15) What is a Data Type and List the different Data types? Ans: C data types are defined as the data storage format that a variable can store a data to perform a specific operation.647 to 2.295 Unsigned long 13 8 2(power)64 –1 long int Prepared By: P.483.967. structure.483.294. Char. • The storage size of int data type is 2 or 4 or 8 byte.483. Float.767 to 32.147.767 • int (4 byte) can store values from -2.147.

22) How many Keywords are there in C and List out the Keywords? Ans : There are 33 reserved keywords are there in C. • It start with 0 (zero) by default and value is incremented by 1 for the sequential identifiers in the list. and % within identifiers. We can write in between /* and */ or // (Line Comments) 20) What is an Identifier in C? Ans: A C identifier is a name used to identify a variable. HARI SHANKAR . 21) What is a Key word in C? Ans: Keywords are reserved words in C and Keywords are may not be used as constant or variable or any other identifier names. C is a case sensitive programming language. function. $. An identifier starts with a letter A to Z or a to z or an underscore _ followed by zero or more letters. underscores. or any other user- defined item. 19) What is a comment in C? Ans: Comments are like helping text in your C program and they are ignored by the compiler. They are: auto else long switch break enum register typedef case extern return union char float short unsigned const for signed void continue goto sizeof volatile default if static while do int struct _Packed double Prepared By: P. Syntax: enum identifier { enumerator-list }. C does not allow punctuation characters such as @. 18) What is a Void Data Type? Ans: Void is an empty data type that has no value.Computer Programming Viva Questions 17) What is enum Data Type? Ans: • Enumeration data type consists of named integer constants as a list. and digits (0 to 9).

Logical Errors are determined by analyzing the outputs for different possible inputs that can be applied to the program.”. 26) List some Syntactic Errors or Syntax Errors? Ans: 1) Missing semicolon(Statement Missing .) 2) Undeclared a variable name or Undefined symbol (Then check variable declaration syntax and check for header file for some keywords) 3) ’)’ expected (Then check the no of parenthesis opened and closed) 4) Illegal string constant ( check for the last double quote in a string) 5) printf and scanf arguments should be placed in ( ) 6) Compound statement missing (Check for the no of { and } are opened and closed) 7) Proto type missing error (Check for Function declaration statement) 8) Forgetting to put &.j. 24) What are the steps to develop a C Program? Ans: • Specifying the problem statement • Designing an algorithm • Coding • Debugging • Testing and Validating • Documentation and Maintenance. and comma operator in specific places.Computer Programming Viva Questions 23) Define a Variable? Ans: A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C has a specific type. finding logarithm of negative number. ch. HARI SHANKAR . finding square root of negative number . 25) What is the process of debugging or compilation for C Programs? Ans: To check the errors in a program is called debugging or compilation. Syntax for variable Declaration: DataType VariableList.) 3) Checking Linker Errors: These errors are occurred due to the linking of header file to the current program (Short cut Key : CTRL+F9) 4) Checking Logical Errors: These Errors occur due to incorrect usage of the instruction in the program. cahr c.etc. int i. Prepared By: P. This process done by 3 stage: 1) Checking Syntactic Errors: These errors occur due to the usage of wrong syntax for the statements. (Short cut Key : ALT+F9) 2) Checking Run time Errors/ Linkage Errors: These Errors are determined at the execution time of the program (EX: Divide a number by Zero. which determines the size and layout of the variable's memory.

to compare the values of two variables in a C program.Computer Programming Viva Questions 9) Comparing strings with == operator 27) List some Warnings? Ans: 1) Miss use of = and == 2) Loop has no body ( remove the semicolon at last of the for loop or while loop) 3) Uninitialized a variable 28) What is an Operator and list different types of operators in C? Ans: The symbols which are used to perform logical and mathematical operations in a C program are called C operators. Decimal values are converted into binary values which are the sequence of bits and bit wise operators work on these bits. %=) 31) What are Relational Operators? Ans: Relational operators are used to find the relation between two variables. Bitwise operators. (Like >. <=. (Like: ? and : ) Prepared By: P. There are two types assignment operators are there: 1) Simple Assignment( = ) 2) Compound Assignment (+= .. (Like &. multiplication. subtraction. >> (Right Shift)) 34) What are Conditional (Ternary) Operators? Ans: Conditional operators return one value if condition is true and returns another value is condition is false. *=. (Like &&. ||./. (Like +. i.*. -=. HARI SHANKAR . ^. ==) 32) What are Logical Operators? Ans: These operators are used to perform logical operations on the given expressions. |. >=. Increment and Decrement operators. The different operators in C are: Arithmetic operators.-. !=. Relational operators.e. Special operators 29) What are Arithmetic Operators? Ans: Arithmetic operators are used to perform mathematical calculations like addition. !) 33) What are Bitwise Operators? Ans: These operators are used to perform bit operations. division and modulus in C programs. Assignment operators. ~. Conditional operators. <. Logical operators. <<(Left Shift).%) 30) What are Assignment Operators? Ans: Values for the variables are assigned using assignment operators.

Iterative or Looping Statements. Compound Statement. %p (Address with Hexa Decimal Value in Small Letters). (Like ++. 44) Define Expression Statement? Ans: When an expression statement is executed. * (Pointer Operator). Expression Statement. %s (Strings). 38) What is pre-increment or post-increment? Ans: ++n (pre increment) increments n before its value is used in an assignment operation or any expression containing it. %c (Character). Return Statement. Unconditional Statements 43) Define Null Statement? Ans: A "null statement" is a statement containing only a semicolon. n++ (post increment) does increment after the value of n is used. the expression is evaluated according to the rules outlined in Expressions and Assignments. --) 36) What are Special Operators? Ans: &(Address Operator). 39) What is type casting? Ans: Converting a variable of one type to another type. and Sizeof() 37) What is sizeof operator? Ans: It returns the number of bytes the operand occupies. %l (Long Integer). %x ((Address with Hexa Decimal Value in Capital Letters) 41) What is a Statement in C? Ans: A statement is a block of code that does something. Conditional Statements.Computer Programming Viva Questions 35) What are Increment / Decrement Operators? Ans: Increment operators are used to increase the value of the variable by one and decrement operators are used to decrease the value of the variable by one in C programs. 45) Define Compound Statement? Ans: A compound statement (also called a "block") typically appears as the body of another statement which is in between { and } Prepared By: P. 42) Different Types of Statements? Ans: Null Statement. HARI SHANKAR . %f (Float). 40) What are the Format Specifiers or Type Specifiers or Conversion Specifiers? Ans: %d (Integer). %u (Address with decimal value).

HARI SHANKAR . A return statement can also return a value to the calling function. The Different types of conditional statements are: 1) If Statement 2) If else statement 3) Nested.ELSE Statement? Ans: if ( <expression> ) <statement 1> else <statement 2> 50) Write the Syntax for NESTED.ELSE Statement? Ans: if ( <expression1> ) { if(<expression2>) { <Statements> } else { <Statements> } } else <statement> 51) Write the Syntax for Switch Case Statement? Ans: switch ( <expression> ) ( <case list> } Prepared By: P.IF .Computer Programming Viva Questions 46) Define Return Statement? Ans: The return statement terminates the execution of a function and returns control to the calling function.if else statement 4) Switch Statement 48) Write the Syntax for IF Statement? Ans: if ( <expression> ) <statement> 49) Write the Syntax for IF. 47) Define Conditional Statements and give the list of them? Ans: Conditional Statements which allows to perform actions depending upon some conditions provided by the programmer.

Prepared By: P. 52) What are Iterative or Looping Statements? Ans: Iterative or Looping statement which executes the statements with in the compound statement by checking the condition. The given label must reside in the same function and can appear before only one statement in the same function.Computer Programming Viva Questions where <case list> is a sequence of case <value>: <statement list> break. 58) Define goto and labeled Statement. HARI SHANKAR . for 53) Write Syntax for WHILE Statement? Ans: while ( <expression> ) <statement> 54) Write Syntax for DO.<Increment/Decrement>) <statement> 56) What is the difference between for loop and while loop? Ans: For Loop is used to execute a set of statements in fixed number of times. 55) Write Syntax for FOR Statement? Ans: for ( <Initialization>. do-while.WHILE Statement? Ans: do <statement> while ( <expression> ). The Iterative or Looping Statements are: While. Syntax: goto <label>. and performs same set of statements as a iterative process or as a loop until the condition false. 57) What are Unconditional Statements? Ans: goto and labeled statements.<Condition>. Write syntax for goto and labeled statements? Ans: The goto statement transfers control to a label. break Statement continue Statement. We use While loop when the number of iterations to be performed is not known in advance we use while loop. and optionally one default: <statement list> break. <label>: <Statement>.

60) Define Continue Statement. Syntax: const data_type variable_name. or while statement in which it appears. keywords. They are also called as literals. (or) volatile data_type *variable_name. Prepared By: P. They are. and statements or expressions. for. HARI SHANKAR . 64) What is a Macro? Ans: Macros are the identifiers that represent statements or expressions. Syntax: break. or while statement in which it appears Syntax: continue. the program may not change the value of the variable explicitly.Computer Programming Viva Questions 59) Define Break Statement. To associate meaningful identifiers with constants. Write syntax for Continue statement? Ans: The continue statement passes control to the next iteration of the nearest enclosing do. #include “ ” Specifically used for used for user defined/created n header file. They refer to fixed values. 65) What is the difference between #include< > and #include “ ”? Ans: #include‹ › Specifically used for built in header files. switch. 63) Define volatile Keyword with Syntax? Ans: When a variable is defined as volatile. and list them? Ans: The keywords which are used to modify the properties of a variable are called type qualifiers. for. Syntax: volatile data_type variable_name. Control passes to the statement that follows the terminated statement. 61) Define Type Qualifiers. (or) const data_type *variable_name. There are two types of qualifiers available in C language. Write syntax for Break statement? Ans: The break statement terminates the execution of the nearest enclosing do.1) const 2) volatile 62) Define const Keyword with Syntax? Ans: Constants are also like normal variables.

and stored ata different locations. HARI SHANKAR . 1) Auto 2) Extern 3) Static 4) Register Initial / Storage Storage S. default Scope Life Specifier place value CPU Garbage Within the function 1 auto local Memory value only. Till the end of the main CPU program. 69) Types of an Array? Ans: There are 2 types of C arrays. Syntax: storage_specifier data_type variable _name 67) What are Different Storage Classes. Prepared By: P. They are. Register Garbage 4 register local Within the function memory value 68) Define Array? Ans: C Array is a collection of variables belongings to the same data type. Explain in brief? Ans: There are 4 storage class specifiers available in C language.Computer Programming Viva Questions 66) Define Storage class with Syntax? Ans: Storage class specifiers in C language tells the compiler where to store a variable. They are. Variable 2 extern Zero Global memory definition might be anywhere in the C program Retains the value of CPU the variable 3 static Zero local memory between different function calls. how to store the variable.No. You can store group of data of same data type in an array. OR An Array is a collection of Homogeneous or similar data type elements having unique values. what is the initial value of the variable and life time of the variable.

age[0]. str[1]. Initialization. accessing the elements? Ans: Two dimensional array is nothing but array of array._/*1_is_accessed*/ age[2].0}. value3. 72) What is the syntax for One Dimensional Array. syntax : data_type array_name[num_of_rows][num_of_column] S. arr_name (value1. [num_of_rows][num_of_column]. Array Array initialization Accessing array declaration Syntax: data_type arr_name data_type [arr_size]= arr_name[index]. explain declaration. age[1]. {{0._/*H is accessed*/ char char str[0] = ‘H’. value2.2. accessing the elements? Ans: Syntax : data-type arr_name[array_size]. [arr_size]. Array name represents the address of the starting element 71) What is the syntax for One Dimensional Array.‘a’. 2.1}._/*0_is_accessed*/ int age [5]. arr [0] [0] = 1. Prepared By: P. 1. HARI SHANKAR . 5}.‘i’}.0}. 4._/*2_is_accessed*/ char str[10]={‘H’. Array elements are stored in subsequent memory locations Two-dimensional array elements are stored row by row in subsequent memory locations. four dimensional array etc… 70) What are the Characteristics of Arrays? Ans: An array holds elements that have the same data type. /* i is accessed*/ char str[2] = ‘i. char str[1] = ‘a’.….). int age[5]={0. (or) str[0]. explain declaration. str[2]. 3.1}}. 3.{1. 4}. 2 Example: int arr[2][2] = {1. Initialization.{ Array declaration Array initialization Accessing array Syntax: data_type arr_name[2][2] 1 data_type arr_name = arr_name[index]. /*a is accessed*/ str[10].{0.Computer Programming Viva Questions 1) One dimensional array 2) Multi dimensional array i) Two dimensional array ii) Three dimensional array.

Computer Programming Viva Questions int arr[2][2]. ‘o’ .n).str2). strchr(). 75) Header used for String Functions? Ans: #include<string. Prepared By: P. strncpy(). strcmp(). strchr() Returns pointer to first occurrence of char Strrchr(str. ‘l’ .str2). Whereas. another string strcmpi() Same as strcmp() function.str2). strcmpi().str2. <0 if strl < str2. strncmp() Compares some portion of a string in Strncmp(str1. strncpy() copies given number of characters of one Strcpy(str1. (or) char string [] = “Hello”. (First n string characters of str2 are appends to str1) strcmp() Returns 0 if str1 is same as str2. strrev() Function Description Syntax Name strcat() Concatenates str2 at the end of str1. Returns Strcmp(str1. strrchr(). “A” and “a” are treated as same. arr [1][0] = 3.’charcater’). ‘###BOT_TEXT###’}. this Strcmpi(str1. arr [1] [1] = 4. strcpy().strrstr().h> 76) List String Handling Functions or String Manipulation Functions? Ans: strcat(). strlen(). strncat() appends a portion of string to another Strcat(str1. Strcat(str1. arr [0] ]1] = 2. Strings are always enclosed by double quotes. strstr(). ‘e’ . function negotiates case.str2. strcpy() Copies str2 into str1 Strcpy(str1. (or) char string[20] = “Hello”.n). string to another strlen() gives the length of string.str2. strncmp(). HARI SHANKAR . Example: char string[20] = { ‘H’ .n). Strlen(str). Returns >0 if str1 > str2. But. strncat(). 73) How we can read or print the array elements? Ans: To read or print the array elements we need to use FOR Statement 74) Define a String? Ans: C Strings are nothing but array of characters ended with null character (‘###BOT_TEXT###’). character is enclosed by single quotes in C.str2). ‘l’ .

Strrev() reverses the given string Strstr(str1). linked list etc. at run time. 80) What is the invalid pointer Arithmetic? Ans: adding . 78) Define Pointer with Syntax and example? Ans: C Pointer is a variable that stores/points the address of another variable. It is used for dynamic memory allocation. Example : int *p. It is used in data structures like can be treated as a one dimensional array of characters terminated by a NULL character.str2).str2). Shifting or masking pointer. C Pointer is used to allocate memory dynamically i. string is found strstr() Returns pointer to first occurrence of str2 Strstr(str1. strrchr() last occurrence of given character in a Strrchr(str.Computer Programming Viva Questions in str1. in str1. graph.e. The number attached to a memory location is called the address of the location. HARI SHANKAR . 79) What are the uses of Pointers? Ans: Pointer is used in the following cases It is used to access array elements. 82) How are Pointer Variables initialized? Ans: Pointer variable are initialized in two ways: Static memory allocation Prepared By: P. strrstr() Returns pointer to last occurrence of str2 Strstr(str1. Each memory location is numbered in the memory. It is used in Call by reference.multiplying and dividing two pointers. in str1. 77) What is the difference between strings and arrays? Ans: String is a sequence of characters ending with NULL . Syntax: data_type *var_name. char *p. Addition of float or double to pointer Assignment of a pointer of one type to a pointer of another type 81) What is a pointer value and address? Ans: A pointer value is a data object that refers to a memory location.’charcater’).

It also reduces the Time to run a program. Easier to exchange the strings by moving their pointers while sorting. Here p2 is a pointer to a pointer. float *f( ) . Prepared By: P. Function are easily understanding and reliability and execution is faster. HARI SHANKAR . Such a situation is known as a pointer to a pointer.g . Pointer to apointer to int pointer to a data type . int *a[10].g. e.malloc () for allocating the single block of memory.e. p2=&p1.Computer Programming Viva Questions Dynamic memory allocation 83) What is a pointer to pointer? Ans: If a pointer variable points another pointer value. 88) What is the difference between malloc( ) and calloc( ) Functions? Ans: • Malloc is used for memory allocation and initialize garbage values. Example : int *p1.g. Syntax: *ptr-variable=(type-casting*)malloc(n*sizeof(DataType)) Example: *ptr=(int*)malloc(5*sizeof(int)). int (*a)[10]. pointer to char 86) What are the Advantages of Functions? Ans: It reduces the Complexity in a program by reducing the code.P1=&v. Its easy to find-out the errors due to the blocks made as function definition outside the main function.g . Array of pointers to integer Pointers to an array. 87) What is Recursion? Ans: A recursion function is one which calls itself either directly or indirectly it must halt at a definite point to avoid infinite recursion. int **x.e. 84) What are the advantages of using array of pointers to string instead of an array of strings? Ans: Efficient use of memory.g. Pointer to an array of into Function returning a pointer. v=10.In other way. Function returning a pointer to float Pointer to a pointer .e. Its directly proportional to Complexity. **p2. char *p.e. 85) What are the pointer declarations used in C? Ans: Array of pointers.

The size may be increased or decreased. • The core concept of C functions are. • There is no limit in calling C functions to make use of same functionality wherever required. 90) What is an Argument? Ans: An argument is an entity used to pass data from the calling to a called function. re-usability. C function S.n) uses two arguments. dividing a big task into small pieces to achieve the functionality and to improve understandability of very large C programs. • A large C program can easily be tracked when it is divided into functions. They are also known as library functions. The first argument ptr is a pointer to a block of memory for which the size is to be altered. Function Call and Function Definition with Syntaxes: Ans: • Function declaration or prototype .This informs compiler about the function name.Computer Programming Viva Questions • Calloc is same as malloc but it initialize 0 value. • We can call functions any number of times in a program and from any place in a program. Prepared By: syntax aspects function return_type function_name ( arguments list ) 1 definition { Body of function. 91) What are Built-in-Functions/ Pre Defined Functions / Library Functions? Ans: The functions that are predefined and supplied along with the compiler are known as built in functions. The function realloc (ptr. The second argument specifies the new size. 92) What are the uses of Functions? Ans: • C functions are used to avoid rewriting same logic/code again and again in a program. If sufficient space is not available to the old region the function may create a new region.sizeof(DataType)) Example: *ptr=(int*)calloc(5. 93) Define Function Declaration. HARI SHANKAR . • Function call – This calls the actual function • Function definition – This contains all the statements to be executed. function parameters and return value’s data type.calloc () for allocating multiple blocks of memory.sizeof(int)). } 2 function call function_name ( arguments list ). 89) What is the purpose of realloc? Ans: It increases or decreases the size of dynamically allocated array. Syntax: *ptr-variable=(type-casting*)calloc(n.

} int function ( ). the address of the variable is passed to the function as parameter. // function call 4 and with int function( ) // function definition return values {statements. // function declaration with arguments and function ( a ).} 97) List some MATH. • Actual parameter – This is the argument which is used in function call.} void function ( int ). // function declaration without arguments function(). • Formal parameter – This is the argument which is used in function definition 95) Define Call by Reference? Ans: In call by reference method. Different Memory is allocated for both actual and formal parameters. // function call 1 with int function( int a ) // function definition return values {statements. // function call 2 without void function( int a ) // function definition return values {statements. Same memory is used for both actual and formal parameters since only address is used by both parameters. 96) Explain the Categories of Functions? Ans: S.Computer Programming Viva Questions function 3 return_type function_name ( argument list ). declaration 94) Define Call by Value? Ans: In call by value Function Description 1 abs ( ) This function returns the absolute value of an integer.} void function(). return C function syntax int function ( int ). the value of the variable is passed to the function as parameter. // function declaration with arguments and function( a ).H Functions? Ans: S. // function declaration without arguments function ( ). The value of the actual parameter can not be modified by formal parameter. The value of the actual parameter can be modified by formal parameter. // function call 3 and without void function() // function definition return values {statements. return a. The Prepared By: P. HARI SHANKAR .

5″. If decimal value is from “. This function returns the nearest integer value of the float/double/long double argument passed to this function. This function truncates the decimal value from floating 7 trunc() point value and returns integer value.1 to . If decimal value is from ”. it returns the integer value greater than the argument. This function is used to find square root of the argument 5 sqrt ( ) passed to this function. This function returns the nearest integer which is less than 2 floor ( ) or equal to the argument passed to this function. 6 pow ( ) This is used to find the power of the given number. This function returns nearest integer value which is greater 4 ceil ( ) than or equal to the argument passed to this function. Prepared By: P.) integer value less than the argument. it returns 3 round.6 to .Computer Programming Viva Questions absolute value of a number is always positive. HARI SHANKAR .(.9″. Only integer values are supported in C.