Top 130 C Programming Interview Questions & Answers

Booster Dose......


1. What does static variable mean?

Ans: Static variables are the variables which retain their values between the function calls. They are initialized only once their scope is within the function in which they are defined.

2. What is a pointer?

Ans: Pointers are variables which stores the address of another variable. That variable may be a scalar (including another pointer), or an aggregate (array or structure). The pointed-to object maybe part of a larger object, such as a field of a structure or an element in an array.

3. What are the uses of a pointer?

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

4. In header files whether functions are declared or defined?

Ans: Functions are declared within header file. That is function prototypes exist in a header file,not function bodies. They are defined in library (lib).

5. What are the differences between malloc ( ) and calloc ( )?

Ans: Malloc Calloc 1-Malloc takes one argument Malloc(a);where a number of bytes 2-memory allocated contains garbage values:-

1-Calloc takes two arguments Calloc(b,c) where b no of object and c size of object.

2-It initializes the contains of block of memory to zeros Malloc takes one argument, memory allocated contains garbage values.

It allocates contiguous memory locations. Calloc takes two arguments, memory allocated contains all zeros, and the memory allocated is not contiguous.

6. What are macros? What are its advantages and disadvantages?

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

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

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

8. What is static identifier?

Ans: A file-scope variable that is declared static is visible only to functions within that file. A function-scope or block-scope variable that is declared as static is visible only within that scope. Furthermore, static variables only have a single instance. In the case of function- or block-scope variables, this means that the variable is not ―automatic‖ and thus retains its value across function invocations.

9. Where is the auto variables stored?

Ans: Auto variables can be stored anywhere, so long as recursion works. Practically, they‘re stored on the stack. It is not necessary that always a stack exist. You could theoretically allocate function invocation records from the heap.

10. Where does global, static, and local, register variables, free memory and C Program instructions get stored?

Ans: Global: Wherever the linker puts them. Typically the ―BSS segment‖ on many platforms. Static: Again, wherever the linker puts them. Often, they‘re intermixed with the globals. The only difference between globals and statics is whether the linker will resolve the symbols across compilation units.Local: Typically on the stack, unless the variable gets register allocated and never spills.Register: Nowadays, these are equivalent to ―Local‖ variables. They live on the stack unless they get register-allocated.

11. Difference between arrays and linked list?

Ans: An array is a repeated pattern of variables in contiguous storage. A linked list is a set of structures scattered through memory, held together by pointers in each element that point to the next element. With an array, we can (on most architectures) move from one element to the next by adding a fixed constant to the integer value of the pointer. With a linked list, there is a ―next‖ pointer in each structure which says what element comes next.

12. What are enumerations?

Ans: They are a list of named integer-valued constants. Example:enum color { black , orange=4 yellow, green, blue, violet };This declaration defines the symbols ―black‖, ―orange‖, ―yellow‖, etc. to have the values ―1,‖ ―4,‖ ―5,‖ … etc. The difference between an enumeration and a macro is that the enum actually declares a type, and therefore can be type checked.

13. Describe about storage allocation and scope of global, extern, static, local and register variables?

Ans: Globals have application-scope. They‘re available in any compilation unit that includes an appropriate declaration (usually brought from a header file). They‘re stored wherever the linker puts them, usually a place called the ―BSS segment.‖ Extern? This is essentially ―global.‖ Static: Stored the same place as globals, typically, but only available to the compilation unit that contains them. If they are block-scope global, only available within that block and its subblocks.

Local: Stored on the stack, typically. Only available in that block and its subblocks.(Although pointers to locals can be passed to functions invoked from within a scope where that local is valid.)

Register: See tirade above on ―local‖ vs. ―register.‖ The only difference is that the C compiler will not let you take the address of something you‘ve declared as ―register.‖

14. What are register variables? What are the advantages of using register variables?

Ans: If a variable is declared with a register storage class,it is known as register variable.The register variable is stored in the cpu register instead of main memory.Frequently used variables are declared as register variable as it‘s access time is faster.

15. What is the use of typedef?

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

16. Can we specify variable field width in a scanf() format string? If possible how?

Ans: All field widths are variable with scanf(). You can specify a maximum field width for a given field by placing an integer value between the ‗%‘ and the field type specifier. (e.g. %64s). Such a specifier will still accept a narrower field width.The one exception is %#c (where # is an integer). This reads EXACTLY # characters, and it is the only way to specify a fixed field width with scanf().

17. Out of fgets() and gets() which function is safe to use and why?

Ans: fgets() is safer than gets(), because we can specify a maximum input length. Neither one is completely safe, because the compiler can‘t prove that programmer won‘t overflow the buffer he pass to fgets ().

18. Difference between strdup and strcpy?

Ans: Both copy a string. strcpy wants a buffer to copy into. strdup allocates a buffer using malloc(). Unlike strcpy(), strdup() is not specified by ANSI .

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

20. Differentiate between for loop and a while loop? What are it uses?

Ans: For executing a set of statements fixed number of times we use for loop while when the number of iterations to be performed is not known in advance we use while loop.

21. What is storage class? What are the different storage classes in C?

Ans: Storage class is an attribute that changes the behavior of a variable. It controls the lifetime, scope and linkage. The storage classes in c are auto, register, and extern, static, typedef.

22. What is the difference between Strings and Arrays?

Ans: String is a sequence of characters ending with NULL .it can be treated as a one dimensional array of characters terminated by a NULL character.

23. What is a far pointer? Where we use it?

Ans: In large data model (compact, large, huge) the address B0008000 is acceptable because in these model all pointers to data are 32bits long. If we use small data model(tiny, small, medium) the above address won‘t work since in these model each pointer is 16bits long. If we are working in a small data model and want to access the address B0008000 then we use far pointer. Far pointer is always treated as a 32bit pointer and contains a segment address and offset address both of 16bits each. Thus the address is represented using segment : offset format B000h:8000h. For any given memory address there are many possible far address segment : offset pair. The segment register contains the address where the segment begins and offset register contains the offset ofdata/code from where segment begins.

24. What is a huge pointer?

Ans: Huge pointer is 32bit long containing segment address and offset address. Huge pointers are normalized pointers so for any given memory address there is only one possible huge address segment: offset pair. Huge pointer arithmetic is doe with calls to special subroutines so its arithmetic slower than any other pointers.

25. What is a normalized pointer, how do we normalize a pointer?

Ans: It is a 32bit pointer, which has as much of its value in the segment register as possible. Since a segment can start every 16bytes so the offset will have a value from 0 to F. for normalization convert the address into 20bit address then use the 16bit for segment address and 4bit for the offset address. Given a pointer 500D: 9407,we convert it to a 20bitabsolute address 549D7,Which then normalized to 549D:0007.

26. What is near pointer?

Ans: A near pointer is 16 bits long. It uses the current content of the CS (code segment) register(if the pointer is pointing to code) or current contents of DS (data segment) register (if the pointer is pointing to data) for the segment part, the offset part is stored in a 16 bit near pointer. Using near pointer limits the data/code to 64kb segment.

27. In C, why is the void pointer useful? When would you use it?

Ans: The void pointer is useful because it is a generic pointer that any pointer can be cast into and back again without loss of information.

28. What is a NULL Pointer? Whether it is same as an uninitialized pointer?

Ans: Null pointer is a pointer which points to nothing but uninitialized pointer may point to anywhere.

29. Are pointers integer?

Ans: No, pointers are not integers. A pointer is an address. It is a positive number.

30. What does the error ‘Null Pointer Assignment’ means and what causes this error?

Ans: As null pointer points to nothing so accessing a uninitialized pointer or invalid location may cause an error.

31. What is generic pointer in C?

Ans: In C void* acts as a generic pointer. When other pointer types are assigned to generic pointer, conversions are applied automatically (implicit conversion).

32. Are the expressions arr and &arr same for an array of integers?

Ans: Yes for array of integers they are same.

33. How pointer variables are initialized?

Ans: Pointer variables are initialized by one of the following ways.

        I. Static memory allocation

        II. Dynamic memory allocation

34. What is static memory allocation?

Ans: Compiler allocates memory space for a declared variable. By using the address of operator, the reserved address is obtained and this address is assigned to a pointer variable. This way of assigning pointer value to a pointer variable at compilation time is known as static memory allocation.

35. What is dynamic memory allocation?

Ans: A dynamic memory allocation uses functions such as malloc() or calloc() to get memory dynamically. If these functions are used to get memory dynamically and the values returned by these function are assigned to pointer variables, such a way of allocating memory at run time is known as dynamic memory allocation.

36. What is the purpose of realloc?

Ans: It increases or decreases the size of dynamically allocated array. The function realloc (ptr,n) uses two arguments. The first argument ptr is a pointer to a block of memory for which the size is to be altered. The second argument specifies the new size. The size may be increased or decreased. If sufficient space is not available to the old region the function may create a new region.

37. What is pointer to a pointer?

Ans: If a pointer variable points another pointer value. Such a situation is known as a pointer to apointer.

    Example:

        int *p1,**p2,v=10;

        P1=&v; p2=&p1;

        Here p2 is a pointer to a pointer.

38. What is an array of pointers?

Ans: If the elements of an array are addresses, such an array is called an array of pointers.

39. Difference between linker and linkage?

Ans: Linker converts an object code into an executable code by linking together the necessary built in functions. The form and place of declaration where the variable is declared in a program determine the linkage of variable.

40. Is it possible to have negative index in an array?

Ans: Yes it is possible to index with negative value provided there are data stored in this location. Even if it is illegal to refer to the elements that are out of array bounds, the compiler will not produce error because C has no check on the bounds of an array.

41. Why is it necessary to give the size of an array in an array declaration?

Ans: When an array is declared, the compiler allocates a base address and reserves enough space in memory for all the elements of the array. The size is required to allocate the required space and hence size must be mentioned.

42. What modular programming?

Ans: If a program is large, it is subdivided into a number of smaller programs that are called modules or subprograms. If a complex problem is solved using more modules, this approach is known as modular programming.

43. What is a function?

Ans: A large program is subdivided into a number of smaller programs or subprograms. Each subprogram specifies one or more actions to be performed for the larger program. Such sub programs are called functions.

44. What is an argument?

Ans: An argument is an entity used to pass data from the calling to a called function.

45. What are built in functions?

Ans: The functions that are predefined and supplied along with the compiler are known as builtin functions. They are also known as library functions.

46. Difference between formal argument and actual argument?

Ans: Formal arguments are the arguments available in the function definition. They are preceded by their own data type. Actual arguments are available in the function call. These arguments are given as constants or variables or expressions to pass the values to the function.

47. Is it possible to have more than one main() function in a C program ?

Ans: The function main() can appear only once. The program execution starts from main.

48. What is the difference between an enumeration and a set of pre-processor # defines?

Ans: There is hardly any difference between the two, except that #defines has a global effect (throughout the file) whereas an enumeration can have an effect local to the block if desired. Some advantages of enumeration are that the numeric values are automatically assigned whereas in #define we have to explicitly define them. A disadvantage is that we have no control over the size of enumeration variables.

49. Write a program which employs Recursion?

Ans: int fact(int n) { return n > 1 ? n * fact(n – 1) : 1; }

50.Write a program which uses Command Line Arguments?

Ans:

    #include

    void main(int argc,char *argv[])

    {

        int i;

        clrscr();

        for(i=0;i

        printf(―\n%d‖,argv[i]);

    }

51. Difference between array and pointer?

Ans:

    Array

        1- Array allocates space automatically

        2- It cannot be resized

        3- It cannot be reassigned

        4- sizeof (arrayname) gives the number of bytes occupied by the array.

    Pointer

        1-Explicitly assigned to point to an allocated space.

        2-It can be sized using realloc()

        3-pointer can be reassigned.

        4-sizeof (p) returns the number of bytes used to store the pointer variable p.

52. What do the ‘c’ and ‘v’ in argc and argv stand for?

Ans: The c in argc(argument count) stands for the number of command line argument the program is invoked with and v in argv(argument vector) is a pointer to an array of character string that contain the arguments.

53. what are C tokens?

Ans: There are six classes of tokens: identifier, keywords, constants, string literals, operators and other separators.

54. What are C identifiers?

Ans: These are names given to various programming element such as variables, function, arrays.It is a combination of letter, digit and underscore.It should begin with letter. Backspace is not allowed.

55. Difference between syntax vs logical error?

Ans:

    Syntax Error

        1-These involves validation of syntax of language.

        2-compiler prints diagnostic message.

    Logical Error

        1-logical error are caused by an incorrect algorithm or by a statement mistyped in such a way that it doesn‘t violet syntax of language.

        2-difficult to find.

56. What is preincrement and post increment?

Ans: ++n (pre increment) increments n before its value is used in an assignment operation or any expression containing it. n++ (post increment) does increment after the value of n is used.

57. Write a program to interchange 2 variables without using the third one.

Ans:

        a ^= b; ie a=a^b

        b ^= a; ie b=b^a;

        a ^= b ie a=a^b;

here the numbers are converted into binary and then xor operation is performed.

You know, you‘re just asking ―have you seen this overly clever trick that‘s not worth applying on modern architectures and only really applies to integer variables?‖

58. What is the maximum combined length of command line arguments including the space between adjacent arguments?

Ans: It depends on the operating system.

59. What is a preprocessor, what are the advantages of preprocessor?

Ans: A preprocessor processes the source code program before it passes through the compiler.

        1- a preprocessor involves the readability of program

        2- It facilitates easier modification

        3- It helps in writing portable programs

        4- It enables easier debugging

        5- It enables testing a part of program

        6- It helps in developing generalized program

60. What are the facilities provided by preprocessor?

Ans:

        1-file inclusion

        2-substitution facility

        3-conditional compilation

61. What are the two forms of #include directive?

Ans:

        1.#include‖filename‖

        2.#include

the first form is used to search the directory that contains the source file.If the search fails in the home directory it searches the implementation defined locations.In the second form ,the preprocessor searches the file only in the implementation defined locations.

62. How would you use the functions randomize( ) and random( )?

Ans:

Randomize() initiates random number generation with a random value.

Random() generates random number between 0 and n-1;

63. What do the functions atoi( ), itoa( ) and gcvt( ) do?

Ans:

    atoi( ) is a macro that converts integer to character.

    itoa( ) It converts an integer to string

    gcvt( ) It converts a floating point number to string

64. How would you use the functions fseek(), freed(), fwrite() and ftell()?

Ans:

    fseek(f,1,i) Move the pointer for file f a distance 1 byte from location i.

    fread(s,i1,i2,f) Enter i2 dataitems,each of size i1 bytes,from file f to string s.

    fwrite(s,i1,i2,f) send i2 data items,each of size i1 bytes from string s to file f.

    ftell(f) Return the current pointer position within file f.

The data type returned for functions fread,fseek and fwrite is int and ftell is long int.

65. What is the difference between the functions memmove( ) and memcpy( )?

Ans: The arguments of memmove( ) can overlap in memory. The arguments of memcpy( ) cannot.

66. What is a file pointer?

Ans: The pointer to a FILE data type is called as a stream pointer or a file pointer. A file pointer points to the block of information of the stream that had just been opened.

67. How is fopen( )used ?

Ans: The function fopen() returns a file pointer. Hence a file pointer is declared and it is assigned as

        FILE *fp;

        fp= fopen(filename,mode);

filename is a string representing the name of the file and the mode represents:

    ―r‖ for read operation

    ―w‖ for write operation

    ―a‖ for append operation

    ―r+‖,‖w+‖,‖a+‖ for update operation

68.How is a file closed ?

Ans: A file is closed using fclose() function Eg. fclose(fp); Where fp is a file pointer.

69. What is the purpose of ftell ?

Ans: The function ftell() is used to get the current file represented by the file pointer. ftell(fp); returns a long integer value representing the current file position of the file pointed by the file pointer fp.If an error occurs ,-1 is returned.

70. What is the purpose of rewind( ) ?

Ans: The function rewind is used to bring the file pointer to the beginning of the file. Rewind(fp); Where fp is a file pointer.Also we can get the same effect by feek(fp,0,0);

71. Difference between a array name and a pointer variable?

Ans: A pointer variable is a variable where as an array name is a fixed address and is not a variable. A pointer variable must be initialized but an array name cannot be initialized. An array name being a constant value , ++ and — operators cannot be applied to it.

72. Represent a two-dimensional array using pointer?

Ans:

        Address of a[I][j] Value of a[I][j]

        &a[I][j]

        or

        a[I] + j

        or

        *(a+I) + j

        *&a[I][j] or a[I][j]

        or

        *(a[I] + j )

        or

        *( * ( a+I) +j )

73. Difference between an array of pointers and a pointer to an array?

Ans:

    Array of pointers

        1- Declaration is: data_type *array_name[size];

        2-Size represents the row size.

        3- The space for columns may be dynamically

    Pointers to an array

        1-Declaration is data_type ( *array_name)[size];

        2-Size represents the column size.

74. Can we use any name in place of argv and argc as command line arguments ?

Ans: yes we can use any user defined name in place of argc and argv;

75. What are the pointer declarations used in C?

Ans:

    1- Array of pointers, e.g , int *a[10]; Array of pointers to integer

    2-Pointers to an array,e.g , int (*a)[10]; Pointer to an array of into

    3-Function returning a pointer,e.g, float *f( ) ; Function returning a pointer to float

    4-Pointer to a pointer ,e.g, int **x; Pointer to apointer to int

    5-pointer to a data type ,e.g, char *p; pointer to char

76. Differentiate between a constant pointer and pointer to a constant?

Ans:

        const char *p; //pointer to a const character.

        char const *p; //pointer to a const character.

        char * const p; //const pointer to a char variable.

        const char * const p; // const pointer to a const character.

77. Is the allocated space within a function automatically deallocated when the function returns?

Ans: No pointer is different from what it points to .Local variables including local pointers variables in a function are de-allocated automatically when function returns.,But in case of a local pointer variable ,de-allocation means that the pointer is de-allocated and not the block of memory allocated to it. Memory dynamically allocated always persists until the allocation is freed or the program terminates.

78. Discuss on pointer arithmetic?

Ans:     1- Assignment of pointers to the same type of pointers.

             2- Adding or subtracting a pointer and an integer.

             3-subtracting or comparing two pointer.

             4-incrementing or decrementing the pointers pointing to the elements of an array. When a pointer to an integer is incremented by one , the address is incremented by two. It is done automatically by the compiler.

             5-Assigning the value 0 to the pointer variable and comparing 0 with the pointer. The pointer having address 0 points to nowhere at all.

79. What is the invalid pointer arithmetic?

Ans:

        i) adding ,multiplying and dividing two pointers.

        ii) Shifting or masking pointer.

        iii) Addition of float or double to pointer.

        iv) Assignment of a pointer of one type to a pointer of another type ?

80. What are the advantages of using array of pointers to string instead of an array of strings?

Ans:

        i) Efficient use of memory.

        ii) Easier to exchange the strings by moving their pointers while sorting.

81. Are the expressions *ptr ++ and ++ *ptr same?

Ans: No,*ptr ++ increments pointer and not the value pointed by it. Whereas ++ *ptr increments the value being pointed to by ptr.

82. What would be the equivalent pointer expression foe referring the same element as a[p][q][r][s] ?

Ans : *( * ( * ( * (a+p) + q ) + r ) + s)

83. Are the variables argc and argv are always local to main?

Ans: Yes they are local to main.

84.Can main ( ) be called recursively?

Ans: Yes any function including main ( ) can be called recursively.

85. Why doesn’t this code: a[i] = i++; work?

Ans: The sub expression i++ causes a side effect. it modifies i‘s value. which leads to undefined behavior since i is also referenced elsewhere in the same expression.


86. What is the difference between Call by Value and Call by Reference?

Ans:When using Call by Value, you are sending the value of a variable as parameter to a function, whereas Call by Reference sends the address of the variable. Also, under Call by Value, the value in the parameter is not affected by whatever operation that takes place, while in the case of Call by Reference, values can be affected by the process within the function.

87. What is a stack?

Ans:A stack is one form of a data structure. Data is stored in stacks using the FILO (First In Last Out) approach. At any particular instance, only the top of the stack is accessible, which means that in order to retrieve data that is stored inside the stack, those on the upper part should be extracted first. Storing data in a stack is also referred to as a PUSH, while data retrieval is referred to as a POP.

88. What is a sequential access file?

Ans:When writing programs that will store and retrieve data in a file, it is possible to designate that file into different forms. A sequential access file is such that data are saved in sequential order: one data is placed into the file after another. To access a particular data within the sequential access file, data has to be read one data at a time, until the right one is reached.

89.  What is variable initialization and why is it important?

Ans:This refers to the process wherein a variable is assigned an initial value before it is used in the program. Without initialization, a variable would have an unknown value, which can lead to unpredictable outputs when used in computations or other operations.

90. Differentiate Source Codes from Object Codes?

Ans:Source codes are codes that were written by the programmer. It is made up of the commands and other English-like keywords that are supposed to instruct the computer what to do. However, computers would not be able to understand source codes. Therefore, source codes are compiled using a compiler. The resulting outputs are object codes, which are in a format that can be understood by the computer processor. In C programming, source codes are saved with the file extension .C, while object codes are saved with the file extension .OBJ

91. In C programming, how do you insert quote characters (' and ") into the output screen?

Ans:This is a common problem for beginners because quotes are normally part of a printf statement. To insert the quote character as part of the output, use the format specifiers \' (for single quote), and \" (for double quote).

92. What is the use of a '\0' character?

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

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

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

94. What is the modulus operator?

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

95. Can two or more operators such as \n and \t be combined in a single line of program code?

Ans:Yes, it's perfectly valid to combine operators, especially if the need arises. For example: you can have a code like " printf ("Hello\n\n\'World\'") " to output the text "Hello" on the first line and "World" enclosed in single quotes to appear on the next two lines.

96. Why is it that not all header files are declared in every C program?

Ans:The choice of declaring a header file at the top of each C program would depend on what commands/functions you will be using in that program. Since each header file contains different function definitions and prototype, you would be using only those header files that would contain the functions you will need. Declaring all header files in every program would only increase the overall file size and load of the program, and is not considered a good programming style.

97. When is the "void" keyword used in a function?

Ans:When declaring functions, you will decide whether that function would be returning a value or not. If that function will not return a value, such as when the purpose of a function is to display some outputs on the screen, then "void" is to be placed at the leftmost part of the function header. When a return value is expected after the function execution, the data type of the return value is placed instead of "void".

98. What is wrong with this statement? myName = "Robin";

Ans:You cannot use the = sign to assign values to a string variable. Instead, use the strcpy function. The correct statement would be: strcpy(myName, "Robin");

99. How do you determine the length of a string value that was stored in a variable?

Ans:To get the length of a string value, use the function strlen(). For example, if you have a variable named FullName, you can get the length of the stored string value by using this statement: I = strlen(FullName); the variable I will now have the character length of the string value.

100. Is it possible to initialize a variable at the time it was declared?

Ans:Yes, you don't have to write a separate assignment statement after the variable declaration, unless you plan to change it later on.  For example: char planet[15] = "Earth"; does two things: it declares a string variable named planet, then initializes it with the value "Earth".

101. Why is C language being considered a middle level language?

Ans:This is because C language is rich in features that make it behave like a high level language while at the same time can interact with hardware using low level methods. The use of a well structured approach to programming, coupled with English-like words used in functions, makes it act as a high level language. On the other hand, C can directly access memory structures similar to assembly language routines.

102. What are the different file extensions involved when programming in C?

Ans:Source codes in C are saved with .C file extension. Header files or library files have the .H file extension. Every time a program source code is successfully compiled, it creates an .OBJ object file, and an executable .EXE file.

103. What are reserved words?

Ans:Reserved words are words that are part of the standard C language library. This means that reserved words have special meaning and therefore cannot be used for purposes other than what it is originally intended for. Examples of reserved words are int, void, and return.

104. What are linked list?

Ans:A linked list is composed of nodes that are connected with another. In C programming, linked lists are created using pointers. Using linked lists is one efficient way of utilizing memory for storage.

105. What is FIFO?

Ans:In C programming, there is a data structure known as queue. In this structure, data is stored and accessed using FIFO format, or First-In-First-Out. A queue represents a line wherein the first data that was stored will be the first one that is accessible as well.

106. What are binary trees?

Ans:Binary trees are actually an extension of the concept of linked lists. A binary tree has two pointers, a left one and a right one. Each side can further branch to form additional nodes, which each node having two pointers as well.

107. Not all reserved words are written in lowercase. TRUE or FALSE?

Ans: FALSE. All reserved words must be written in lowercase; otherwise the C compiler would interpret this as unidentified and invalid.

108. What is the difference between the expression "++a"  and "a++"?

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

109. What would happen to X in this expression: X += 15;  (assuming the value of X is 5)

Ans: X +=15 is a short method of writing X = X + 15, so if the initial value of X is 5, then 5 + 15 = 20.

110. In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?

Ans: FALSE. C language is a case sensitive language. Therefore, NAME, name and Name are three uniquely different variables.

111. What is an endless loop?

Ans: An endless loop can mean two things. One is that it was designed to loop continuously until the condition within the loop is met, after which a break function would cause the program to step out of the loop. Another idea of an endless loop is when an incorrect loop condition was written, causing the loop to run erroneously forever. Endless loops are oftentimes referred to as infinite loops.

112. What is a program flowchart and how does it help in writing a program?

Ans: A flowchart provides a visual representation of the step by step procedure towards solving a given problem. Flowcharts are made of symbols, with each symbol in the form of different shapes. Each shape may represent a particular entity within the entire program structure, such as a process, a condition, or even an input/output phase.

113. What is wrong with this program statement? void = 10;

Ans: The word void is a reserved word in C language. You cannot use reserved words as a user-defined variable.

114. Is this program statement valid? INT = 10.50;

Ans: Assuming that INT is a variable of type float, this statement is valid. One may think that INT is a reserved word and must not be used for other purposes. However, recall that reserved words are express in lowercase, so the C compiler will not interpret this as a reserved word.

115. What are actual arguments?

Ans: When you create and use functions that need to perform an action on some given values, you need to pass these given values to that function. The values that are being passed into the called function are referred to as actual arguments.

116. What is a newline escape sequence?

Ans: A newline escape sequence is represented by the \n character. This is used to insert a new line when displaying data in the output screen. More spaces can be added by inserting more \n characters. For example, \n\n would insert two spaces. A newline escape sequence can be placed before the actual output expression or after.

117. What is output redirection?

Ans: It is the process of transferring data to an alternative output source other than the display screen. Output redirection allows a program to have its output saved to a file. For example, if you have a program named COMPUTE, typing this on the command line as COMPUTE >DATA can accept input from the user, perform certain computations, then have the output redirected to a file named DATA, instead of showing it on the screen.

118. What are run-time errors?

Ans: These are errors that occur while the program is being executed. One common instance wherein run-time errors can happen is when you are trying to divide a number by zero. When run-time errors occur, program execution will pause, showing which program line caused the error.

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

Ans: These 2 functions basically perform the same action, which is to get the absolute value of the given value. Abs() is used for integer values, while fabs() is used for floating type numbers. Also, the prototype for abs() is under <stdlib.h>, while fabs() is under <math.h>.

120. What are formal parameters?

Ans: In using functions in a C program, formal parameters contain the values that were passed by the calling function. The values are substituted in these formal parameters and used in whatever operations as indicated within the main body of the called function.

121. What are control structures?

Ans: Control structures take charge at which instructions are to be performed in a program. This means that program flow may not necessarily move from one statement to the next one, but rather some alternative portions may need to be pass into or bypassed from, depending on the outcome of the conditional statements.

122. What are enumerated types?

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

123. What does the function toupper() do?

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

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

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

125. What are multidimensional arrays?

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

126. Which function in C can be used to append a string to another string?

Ans: The strcat function. It takes two parameters, the source string and the string value to be appended to the source string.

127. What is the difference between functions getch() and getche()?

Ans: Both functions will accept a character input value from the user. When using getch(), the key that was pressed will not appear on the screen, and is automatically captured and assigned to a variable. When using getche(), the key that was pressed by the user will appear on the screen, while at the same time being assigned to a variable.

128. Dothese two program statements perform the same output? 1) scanf("%c", &letter);  2) letter=getchar( )

Ans: Yes, they both do the exact same thing, which is to accept the next key pressed by the user and assign it to variable named letter.

129. What are structure types in C?

Ans: Structure types are primarily used to store records. A record is made up of related fields. This makes it easier to organize a group of related data.

130. What does the characters "r" and "w" mean when writing programs that will make use of files?

Ans: "r" means "read" and will open a file as input wherein data is to be retrieved. "w" means "write", and will open a file for output. Previous data that was stored on that file will be erased.


Also Join Us:-

Post a Comment

2 Comments

If you are a good learner please leave a challenging question on comment box for us when you visited this website ( Coding with Fun).