0% found this document useful (0 votes)
22 views10 pages

C PROGRAM VIVA

Uploaded by

tamilarasan.m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views10 pages

C PROGRAM VIVA

Uploaded by

tamilarasan.m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

1.

Basics of C Programming:

What are the basic data types in C?


The basic data types in C are:
o int (integer)
o float (floating point)
o char (character)
o double (double precision floating point)

2. What is C programming language?


o C is a general-purpose, procedural programming language developed by
Dennis Ritchie at Bell Labs in 1972.
3. What is a variable in C?
o A variable is a memory location where data is stored. Each variable has a
specific data type that determines its size and layout in memory.
4. What are the different data types in C?
o Basic data types include int, char, float, and double. C also supports derived
types like arrays, pointers, structures, and unions.
5. What is a constant in C?
o Constants are fixed values that do not change during the execution of a
program. They can be of any basic data type.
6. What is the use of the main() function in C?
o The main() function is the entry point of a C program. Execution of code starts
from the main() function.
7. 2. Operators and Expressions:
8. What are the different types of operators in C?
o Arithmetic operators, Relational operators, Logical operators, Bitwise
operators, Assignment operators, and Unary operators.
9. What is the difference between =, ==, and ===?
o = is the assignment operator, == checks for equality, and === is not used in C
(it exists in other languages like JavaScript for strict comparison).
10. What is operator precedence?
o Operator precedence determines the order in which operators are evaluated in
expressions.
11. What are relational operators?
o Relational operators are used to compare two values. Examples are <, >, <=,
>=, ==, and !=.
12. What is the difference between ++i and i++?
o ++i is pre-increment (increments the value and then uses it), while i++ is post-
increment (uses the value first and then increments it).
13. 3. Control Statements:
14. What is an if statement?
o The if statement checks a condition and executes a block of code if the
condition is true.
15. What is an else if ladder?
o The else if ladder is used to check multiple conditions in sequence.
16. What is the difference between if and switch?
o The if statement can check conditions based on any expression, while the
switch statement checks conditions based only on equality of integers or
characters.
17. What are loops in C?
o Loops are used to execute a block of code repeatedly. Types include for, while,
and do-while.
18. What is the difference between while and do-while loops?
o A while loop checks the condition before executing the code block, whereas a
do-while loop checks the condition after executing the block at least once.
19. What is a break statement?
o The break statement is used to exit from a loop or a switch statement
prematurely.
20. What is a continue statement?
o The continue statement skips the current iteration of a loop and moves to the
next iteration.
21. What is the syntax of a for loop?
22. c
23. Copy code
24. for (initialization; condition; increment/decrement) {
25. // code block
26. }
27. What is the purpose of the return statement?
o The return statement terminates the function and optionally returns a value to
the calling function.
28. 4. Functions:
29. What is a function in C?
o A function is a block of code that performs a specific task. Functions help in
organizing code, reusing it, and improving readability.
30. What is function prototyping?
o Function prototyping declares the function name, return type, and parameters
before its actual definition.
31. What is the difference between a function declaration and a definition?
o A function declaration provides the function signature to the compiler, while
the definition provides the actual code.
32. What is a recursive function?
o A recursive function is a function that calls itself to solve a smaller instance of
the same problem.
33. What is the difference between call by value and call by reference?
o In call by value, a copy of the argument is passed to the function, whereas in
call by reference, the address of the argument is passed.
34. 5. Arrays and Strings:
35. What is an array in C?
o An array is a collection of elements of the same data type stored at contiguous
memory locations.
36. What is the difference between one-dimensional and two-dimensional arrays?
o A one-dimensional array stores elements in a single row, whereas a two-
dimensional array stores elements in rows and columns (like a matrix).
37. How do you initialize an array in C?
38. c
39. Copy code
40. int arr[] = {1, 2, 3, 4};
41. What is a string in C?
o A string is a one-dimensional array of characters, terminated by a null
character (\0).
42. How do you declare and initialize a string in C?
43. c
44. Copy code
45. char str[] = "Hello";
46. How do you find the length of a string in C?
o You can use the strlen() function from the string.h library to find the length of
a string.
47. What is the difference between gets() and scanf() for inputting strings?
o gets() reads a line of text including spaces until a newline, while scanf() stops
reading when it encounters a space.
48. 6. Pointers:
49. What is a pointer?
o A pointer is a variable that stores the address of another variable.
50. How do you declare a pointer in C?
51. c
52. Copy code
53. int *ptr;
54. What is pointer arithmetic?
o Pointer arithmetic involves operations like incrementing or decrementing a
pointer to move to the next or previous memory location.
55. What is the difference between & and * in pointers?
o & is the address-of operator (used to get the address of a variable), while * is
the dereference operator (used to access the value at the address stored in a
pointer).
56. What is a null pointer?
o A null pointer is a pointer that does not point to any memory location.
57. 7. Structures and Unions:
58. What is a structure in C?
o A structure is a user-defined data type that groups different data types together
under a single name.
59. How do you declare a structure in C?
60. c
61. Copy code
62. struct Student {
63. char name[50];
64. int roll;
65. float marks;
66. };
67. What is a union in C?
o A union is similar to a structure, but all members of a union share the same
memory location.
68. What is the difference between structures and unions?
o In a structure, each member has its own memory, while in a union, all
members share the same memory, and only one can be used at a time.
69. 8. File Handling:
70. What is file handling in C?
o File handling refers to reading and writing data to files. The stdio.h library
provides functions like fopen(), fclose(), fread(), and fwrite() for file handling.
71. How do you open a file in C?
72. c
73. Copy code
74. FILE *fp = fopen("filename.txt", "r");
75. What is the difference between text and binary files?
o Text files store data in human-readable form, whereas binary files store data in
a format that is readable by a machine.
76. What is the use of fseek() function in file handling?
o fseek() is used to move the file pointer to a specific location within the file.
77. 9. Preprocessors and Macros:
78. What is a preprocessor directive in C?
o A preprocessor directive begins with a # symbol and instructs the compiler to
perform specific actions before compilation, like including libraries or
defining macros.
79. What is the #define directive?
o The #define directive is used to define constants or macros that are substituted
throughout the code before compilation.
80. What is the difference between #include <file.h> and #include "file.h"?
o #include <file.h> is used for standard library headers, while #include "file.h"
is used for user-defined header files.
81. 10. Miscellaneous:
82. What is typecasting in C?
o Typecasting is the process of converting a variable from one data type to
another.
83. What is a segmentation fault?
o A segmentation fault occurs when a program tries to access memory that it is
not allowed to.
84. What is dynamic memory allocation?
o Dynamic memory allocation allows programs to allocate memory during
runtime
1. What is the basic structure of a C program?
c
Copy code
#include <stdio.h> // Preprocessor directive

int main() { // Main function


// Code block
return 0; // Return statement
}
 The basic structure of a C program includes the header files, main() function,
statements inside the function, and a return statement.
2. What is the use of the #include directive?
 The #include directive is used to include standard or user-defined header files in a C
program, allowing the use of functions like printf() and scanf().
3. What is a comment in C and how is it written?
 Comments are non-executable parts of the code used for explanation. They can be
written as:
o Single-line comment: // This is a single-line comment
o Multi-line comment:
c
Copy code
/* This is
a multi-line
comment */
4. What is a header file?
 A header file contains function declarations and macros. Example: #include <stdio.h>
includes the Standard Input Output library.
5. What is the syntax of a variable declaration?
c
Copy code
int a; // Declares an integer variable
float b; // Declares a floating-point variable
char c; // Declares a character variable
6. What is the syntax for assigning a value to a variable?
c
Copy code
int x = 10; // Assigns 10 to the variable x
7. What is the syntax for an if statement?
c
Copy code
if (condition) {
// Code block if condition is true
}
8. What is the syntax for an if-else statement?
c
Copy code
if (condition) {
// Code block if condition is true
} else {
// Code block if condition is false
}
9. What is the syntax for a for loop?
c
Copy code
for (initialization; condition; increment/decrement) {
// Code block
}
10. What is the syntax for a while loop?
c
Copy code
while (condition) {
// Code block
}
11. What is the syntax for a do-while loop?
c
Copy code
do {
// Code block
} while (condition);
12. What is the syntax for declaring an array?
c
Copy code
int arr[5]; // Declares an integer array with 5 elements
13. What is the syntax for a function declaration?
c
Copy code
return_type function_name(parameter_list);
14. What is the syntax for a function definition?
c
Copy code
return_type function_name(parameter_list) {
// Code block
}
15. What is the syntax for calling a function?
c
Copy code
function_name(arguments);
16. What is the syntax for declaring a pointer?
c
Copy code
int *ptr; // Declares a pointer to an integer
17. What is the syntax for accessing array elements?
c
Copy code
arr[index]; // Accesses the element at position 'index'
18. What is the syntax for switch-case?
c
Copy code
switch (expression) {
case constant1:
// Code block
break;
case constant2:
// Code block
break;
default:
// Default code block
}
19. What is the syntax for reading input using scanf()?
c
Copy code
scanf("%d", &variable); // Reads an integer input and stores it in 'variable'
20. What is the syntax for printing output using printf()?
c
Copy code
printf("The value is: %d", variable); // Prints the value of 'variable'

You might also like