C Programming Viva Questions and Answers

1. Which type of language is C?

Ans- C is a high–level language and general-purpose structured programming language.

2. What is a compiler?

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

3. What is an algorithm?

Ans- The approach or method that is used to solve the problem is called an algorithm.

4. What is a c token and types of c tokens?

Ans- The smallest individual units are known as C tokens. C has six types of tokens Keywords, Constants, Identifiers, Strings, Operators and Special symbols.

5. How many Keywords (reserve word)are in C?

Ans- There are 32 Keywords in the C language.

6. What is an identifier?

Ans- Identifiers are user-defined names given to variables, functions and arrays.

7. What are the Back Slash character constants or Escape sequence characters available in C?

Ans- Back Slash character constant are \t, \n, \0.

8. What is a variable?

Ans- Variables are user-defined names given to memory locations and are used to store values. A variable may have different values at different times during program execution.

9. What are the Data Types present in C?

Ans- Primary or Fundamental Data types (int, float, char), Derived Datatypes(arrays, pointers) and User-Defined data types(structures, unions, enum)

10. How to declare a variable?

Ans- The syntax for declaring variable isdata type variable_name-1, variable_name-2,….variable_name-n;

Example 1: int a, b;

Example 2: float p,q;

11.What is meant by initialization and how do we initialize a variable?

Ans- While declaring a variable assigning value is known as initialization. Variable can be initialized by using assignment operator (=).

12.How many types of operators or there in C?

Ans- C consist Arithmetic Operators (+, -, *, /,%), Relational Operators (<, <=, >, >=, !=), Logical Operators (&&, ||, !), Assignment Operators (=, +=, -=, *=, /=), Increment and Decrement Operators (++, –), Conditional Operator(?:), Bitwise Operators(<<, >>, ~, &, |, ^) and  Special Operators (. , ->, &, *, size of)

13. What is a Unary operator and what are the unary operators present in C?

Ans- An operator which takes only one operand is called a unary operator. C unary operators are Unary plus (+), Unary minus (-), Increment and Decrement operators (++,–), Address of operator (&), Value at operator (*), sizeof operator, ones complement operator (~)

14. What is the use of the modulus (%) operator?

Ans- The modulus operator produces the remainder of an integer division. It cannot be used on floating-point data

15. What is the use of printf and scanf functions in C?

Ans-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

16. Forms of IF statements?

Ans- Simple IF statement, IF-ELSE statement, NESTED IF-ELSE statement and ELSE IF ladder

17. Forms of IF statements?

Ans- Simple IF statement, IF-ELSE statement, NESTED IF-ELSE statement and ELSE IF ladder

18. What is a goto statement?

Ans- GOTO is an unconditional branching statement which transfers control to the specified label.

19. What is a loop?

Ans- Loop is a sequence of statements that runs repeatedly.

20. What are loop control statements in C?

Ans- While do-while and for.

21. What are sections present in for loop?

Ans- Initialization section, conditional section and increment/decrement section.

22. What is the use of break statements?

Ans- The break statement is used to exit from the loop.

23. What is an array?

Ans-The array is a collective name given to similar elements.

24. How can we initialize an array?

Ans- The initializer for an array is a comma-separated list of constant expressions enclosed in braces

 ( { } ). The initializer is preceded by an equal sign ( = ). You do not need to initialize all elements in an array.

25. What is the difference between normal variable and array variable?

Ans- A variable can store only one value at a time whereas an array variable can store several value at a time.

26. What are the types of Arrays?

Ans- A one-Dimensional array, Two-Dimensional array and Multi-Dimensional array

27. What is a character array?

Ans- An array which can store several characters is called character array

28. What is a function?

Ans- The function is a self-contained block of the statement which is used to perform a certain task

29. What are the types of functions?

Ans- C functions are divided into two categories user-defined function and built-in functions

30. Which are called built-in functions?

Ans- Printf, scanf, clrscr, gotoxy, string handling functions and file handling functions

31. What is a recursive function?

Ans- A function calling itself is called function recursion

32. How to pass an array to a function?

Ans- Arrays are passed to a function by sending its address

33. What is a pointer variable?

Ans- A pointer variable is a variable that can store the address of another variable

34. How can we store the address of a variable is a pointer?

Ans- By using the address of the operator we can store the address of a variable in a pointer

35. How many bytes does a pointer variable occupies in memory?

Ans- A pointer variable irrespective of its type it occupies two bytes in memory

36. What are storage classes available in C?

Ans- Auto, static, extern and register

37. What is a structure?

Ans- The structure is user-defined data typed. The structure is a collective name given to dissimilar elements

38. How to excess structure members?

Ans- Structure members can be accessed using the dot operator

39) What are the differences between structures and arrays?

Ans- Structures store dissimilar values whereas arrays stores similar values. One structure variable can be assigned to another structure variable whereas one array variable cannot be assigned to another array variable

40. What is the size of a structure?

Ans- Sum of all the members size is becomes structure size

41. What is a union?

Ans- Union is a user-defined data type that can store a value of different data types

42. What are the types of files we can create using C?

Ans-We can create text and binary files using C

43. What are the file-handling functions present in C?

Ans- fopen, fclose, fgetc, fputc, fgets, fputs, fprintf, fscanf, fread, fwrite, fseek

44. What are the file opening modes present in C?

Ans- r, w, a, r+, w+, a+, rb, wb, rb+, wb+

45. How to access structure members by their pointer?

Ans- We can use structure members using arrow operator with its pointer

46. What is the difference between normal variable and array variable?

Ans- A variable can store only one value at a time whereas an array variable can store several value at a time.

47. How to declare a variable?

Ans- The syntax for declaring the variable is

Datatype variable_name-1,variable_name-2…variable_name-n

48. What are the key features in the C programming language?

Answer: Features are as follows:

  • Portability: It is a platform-independent language.
  • Modularity: Possibility to break down large programs into small modules.
  • Flexibility: The possibility of a programmer to control the language.
  • Speed: C comes with support for system programming and hence it compiles and executes with high speed when compared with other high-level languages.
  • Extensibility: Possibility to add new features by the programmer.

49. What are the basic data types associated with C?

Answer:

  • Int – Represent the number (integer)
  • Float – Number with a fraction part.
  • Double – Double-precision floating-point value
  • Char – Single character
  • Void – Special purpose type without any value.


50. What is the description for syntax errors?

Answer: The mistakes/errors that occur while creating a program are called syntax errors. Misspelled commands or incorrect case commands, an incorrect number of parameters in calling method /function, data type mismatches can be identified as common examples for syntax errors.

51) What is the process to create increment and decrement statement in C?

Answer: There are two possible methods to perform this task.

Use increment (++) and decrement (-) operator.

Example When x=4, x++ returns 5 and x- returns 3.

Use conventional + or – sign.

Example When x=4, use x+1 to get 5 and x-1 to get 3.

52) What are reserved words with a programming language?

Answer: The words that are a part of the standard C language library are called reserved words. Those reserved words have special meaning and it is not possible to use them for any activity other than its intended functionality.

Example: void, return int.

53) What is the explanation for the dangling pointer in C?

Answer: When there is a pointer pointing to a memory address of any variable, but after some time the variable was deleted from the memory location while keeping the pointer pointing to that location is known as a dangling pointer in C.

54) Describe static function with its usage?

Answer: A function, which has a function definition prefixed with a static keyword is defined as a static function. The static function should be called within the same source code.

55) What is the difference between abs() and fabs() functions?

Answer: Both functions are to retrieve absolute value. abs() is for integer values and fabs() is for floating type numbers. Prototype for abs() is under the library file < stdlib.h > and fabs() is under < math.h >.

56) Describe Wild Pointers in C?

Answer: Uninitialized pointers in the C code are known as Wild Pointers. They point to some arbitrary memory location and can cause bad program behavior or program crash.

57) What is the difference between ++a and a++?

Answer: ‘++a”  is called prefixed increment and the increment will happen first on a variable. ‘a++’ is called postfix increment and the increment happens after the value of a variable used for the operations.

58) Describe the difference between = and == symbols in C programming?

Answer: ‘==’ is the comparison operator which is used to compare the value or expression on the left-hand side with the value or expression on the right-hand side.

‘=’ is the assignment operator which is used to assign the value of the right-hand side to the variable on the left-hand side.

59) Explain concept of function in C?

Answer: Prototype function is a declaration of a function with the following information to the compiler.

  • Name of the function.
  • The return type of the function.
  • Parameters list of the function.

The function definition in C contains four main sections.

return_type function_name( parameter list )

{  

      body of the function

}

  • Return Type: Data type of the return value of the function.
  • Function Name: The name of the function and it is important to have a meaningful name that describes the activity of the function.
  • Parameters: The input values for the function that are used to perform the required action.
  • Function Body: Collection of statements that performs the required action.

60) What is a nested loop?

Answer: A loop that runs within another loop is referred to as a nested loop. The first loop is called the Outer Loop and the inside loop is called the Inner Loop. The inner loop executes the number of times defined in an outer loop.