BCSL-021 C Language Programming Lab Viva Questions
1. Who Developed C Language?
C language was developed by Dennis Ritchie in 1970 at Bell Laboratories.
2. Which type of language is C?
C is a high-level language and general purpose structured programming language.
3. What is a compiler?
Compile is a software program that transfer program developed in high level language into executable object code
4. What is IDE?
The process of editing, compiling, running and debugging is managed by a single integratedapplication known as Integrated Development Environment (IDE)
5. What is a program?
A computer program is a collection of the instructions necessary to solve a specific problem.
6. What is an algorithm?
The approach or method that is used to solve the problem is known as algorithm.
7. What is structure of C program?
AC program contains Documentation section, Link section, Definition section, Globaldeclaration section, Main function and other user defined functions
8. What is a C token and types of C tokens?
The smallest individual units are known as C tokens. C has six types of tokens Keywords, Constants, Identifiers, Strings, Operators and Special symbols.
9. What is a Keyword?
Keywords are building blocks for program statements and have fixed meanings and thesemeanings cannot be changed.
10. How many Keywords (reserve words) are in C?
There are 32 Keywords in C language.
11. What is an Identifier?
Identifiers are user-defined names given to variables, functions and arrays.
12. What is a Constant and types of constants in C?
Constants are fixed values that do not change during the program execution. Types of constants are Numeric Constants (Integer and Real) and Character Constants (SingleCharacter, String Constants).
13. What are the Back Slash character constants or Escape sequence charactersavailable in C?
Back Slash character constant are \t, \n, \o
14. What is a variable?
Variables are user-defined names given to memory locations and are used to store values. Avariable may have different values at different times during program execution
15. What are the Data Types present in C?
Primary or Fundamental Data types (int, float, char), Derived Data types(arrays, pointers) and User-Defined data types(structures, unions, enum)
16.How to declare a variable?
The syntax for declaring variable isdata type variable_name-1, variable_name-2,….variable_name-n;
17. What is meant by initialization and how we initialize a variable?
While declaring a variable assigning value is known as initialization. Variable can beinitialized by using assignment operator
18. What are integer variable, floating-point variable and character variable?
A variable which stores integer constants are called integer variable. A variable which storesreal values are called floating- point variable. A variable which stores character constants arecalled character variables.
19.How many types of operator or there in C?
C consist Arithmetic Operators (+, -,,/,%), Relational Operators (<,<, >, >, !=), LogicalOperators (&&, [.!), Assignment Operators (=, +, -, -,/-), Increment and DecrementOperators (++,-), Conditional Operator(?:), Bitwise Operators(<<, >>,, &, 1, “) andSpecial Operators (., >, &, “, sizeof)
20. What is RAM?
RAM – Random Access Memory is a temporary storage medium in a computer. RAM is a volatile memory ie all data stored in RAM will be erased when the computer is switched off.
21. What do mean by network?
Computer networking refers to connecting computers to share data, application software and hardware divices. Networks allow sharing of information among various computers and permit users to share files
22. List a few unconditional control statement in C.
1. break statement
2. continue statement
3. goto statement
4. exit() function
23. 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[]. Synatax of array declaration is
data type array_name[size];
24. 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[][][]….;
25. 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.
26. Mention four important string handling functions in C languages.
There are four important string handling functions in C languages.
strlen();
trcpy();
streat();
strcmp();
The header file #include is used when these functions are called in a C program.
27. Explain about the constants which help in debugging?
A #if directive test can be offered with #else and #else if directives. This allows conditional branching of the program to run sections of the code according to the result. Constants defined with a #define directive can be undefined with the #undef directive. The #ifdef directive has a companion directive #ifndef. These commands can be useful when debugging problem code to hide and unhide sections of the program.
28. 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.
29. 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.
30. Explain about the functions streat() 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.
31. 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
32. Differentiate built-in functions and user-defined functions.
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, s tring.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.
33. 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.
34. 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.
35. What is recursion?
A function calling itself again and again to compute a value is referref to as recursive function or recursion. Recursion is useful for branching processes and is effective where terms are generated successively to compute a value.
36.What is Header file in c?
In C, a header file is a file that contains declarations, function prototypes, macro definitions, and other information that is shared between multiple source files in a program. It serves as a bridge between the source code and the libraries or modules that provide certain functionalities.
Header files have a .h extension and are typically included using the #include preprocessor directive in C source files. When a header file is included, its content is inserted into the source file at the location of the #include directive during the preprocessing stage.
Header files help in modularizing code, promoting code reuse, and improving maintainability. They provide a way to separate interface and implementation, allowing different source files to access the same functions, variables, and other declarations without the need for duplicating the code.
37. What is Pointer in c?
In C, a pointer is a variable that holds the memory address of another variable. It provides a way to indirectly access and manipulate data by referring to the location of that data in memory.
Pointers are often used for dynamic memory allocation, passing arguments by reference, and working with data structures such as arrays, strings, and linked lists. They allow for efficient memory management and provide flexibility in manipulating data.
38. What is #include in c?
In C, #include is a preprocessor directive that is used to include external files, typically header files, into your C program before the actual compilation takes place. It is a way to bring in declarations, definitions, macros, and other content from other files into your program.
39.What is conio.h in c?
In C, conio.h is a header file that stands for “console input/output.” However, it’s important to note that conio.h is not a standard header file defined by the C language standard. Instead, it is a header file specific to certain compilers and platforms, particularly the MS-DOS and Windows environments.
40. What is scanf() in c?
In C, scanf() is a standard library function defined in the stdio.h header file. It stands for “scan formatted” and is used to read input from the standard input stream (usually the keyboard) and store it into variables.
41.What is printf() in c?
In C, printf() is a standard library function defined in the stdio.h header file. It stands for “print formatted” and is used to format and display output on the console or terminal.
42. What is stdio.h in c?
In C, stdio.h is a standard header file that stands for “standard input-output header.” It is part of the C standard library and provides functions, macros, and type definitions for performing input and output operations.
43. What is meant by getch() in c?
In the C programming language, getch() is a non-standard function that is often used to read a single character from the keyboard without echoing it on the screen. It is typically used for simple character-based input in console-based programs or command-line interfaces.
44. Why c is middle level language?
C is often referred to as a “middle-level” programming language because it combines features of both high-level and low-level languages. This categorization is based on the level of abstraction and the degree of control that the language provides to the programmer.
Here are some reasons why C is considered a middle-level language:
High-level abstraction: C provides a higher level of abstraction compared to low-level languages like assembly language. It offers features such as functions, control structures, and a rich set of library functions that make programming easier and more expressive.
Low-level access: C allows direct memory manipulation and provides low-level features such as pointers, which enable fine-grained control over memory and hardware resources. This makes it suitable for system-level programming and interacting with hardware devices.
Efficiency: C allows efficient memory management and low-level programming constructs, making it suitable for writing performance-critical code. It allows direct access to memory and hardware, enabling the optimization of code for speed and efficiency.
Portability: C is relatively portable across different platforms and operating systems. While it is not as platform-independent as some higher-level languages, C code can be easily adapted and compiled on different systems with minimal modifications, thanks to its close relationship with the underlying hardware.
Close to the machine: C provides a level of control over memory, pointers, and data representation that is closer to the underlying machine architecture. It allows explicit memory management, bitwise operations, and direct manipulation of hardware resources.
Easy integration with other languages: C has a standardized Application Binary Interface (ABI), which allows it to be easily integrated with other languages such as C++, Python, and Java. This makes it a popular choice for writing libraries and APIs that can be used by other programming languages.
45. Different between Structure and Union in C.
In C, both structures (struct) and unions (union) are used to define custom data types that can hold multiple variables of different types. However, there are key differences between structures and unions in terms of their memory allocation and usage. Here’s an overview of the differences:
Memory allocation:
Structure: A structure allocates memory for each member variable independently. The total memory occupied by a structure is the sum of the memory required for each member variable, including any padding for alignment purposes.
Union: A union allocates memory that is large enough to hold the largest member variable. Only one member can be accessed at a time, and modifying one member may overwrite the values of other members.
Memory usage:
Structure: Each member of a structure retains its own memory and can be accessed independently. Each member can hold a different value.
Union: Only one member of a union can hold a value at any given time. Changing the value of one member will overwrite the values of other members. Unions are useful when you need to store different types of data in the same memory space, and only one of them is accessed at a time.
Accessing members:
Structure: Members of a structure are accessed using the dot (.) operator. Each member has a unique memory address.
Union: Members of a union are accessed using the dot (.) operator similar to a structure, but only one member can be accessed at a time. All members share the same memory location.
Size:
Structure: The size of a structure is determined by the sum of the sizes of its individual members, potentially padded for alignment.
Union: The size of a union is equal to the size of its largest member, as the memory is shared among all members.
Usage:
Structure: Structures are commonly used to represent a collection of related data, such as a person’s information, a point in 2D/3D space, or a complex data structure like a linked list or tree.
Union: Unions are typically used when memory efficiency is a concern, and only one member needs to be accessed at a time. They are useful in scenarios like representing variant types or creating data structures that can hold different types of data dynamically.