• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

C Interview Questions Answers

Question - 131 : - Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

Answer - 131 : - It’s easier for a C compiler to generate good code for pointers than for subscripts.

Question - 132 : - What is Operator overloading ?

Answer - 132 : - When an operator is overloaded, it takes on an additional meaning relative to a certain class. But it can still retain all of its old meanings. Examples: 1) The operators >> and << may be used for I/O operations because in the header, they are overloaded. 2) In a stack class it is possible to overload the + operator so that it appends the contents of one stack to the contents of another. But the + operator still retains its original meaning relative to other types of data.

Question - 133 : - Write a program to interchange 2 variables without using the third one.

Answer - 133 : - a=7; b=2; a = a + b; b = a - b; a = a - b;

Question - 134 : - Is it better to use malloc() or calloc()?

Answer - 134 : - Both the malloc() and the calloc() functions are used to allocate dynamic memory. Each operates slightly different from the other. malloc() takes a size and returns a pointer to a chunk of memory at least that big: void *malloc( size_t size ); calloc() takes a number of elements, and the size of each, and returns a pointer to a chunk of memory at least big enough to hold them all: void *calloc( size_t numElements, size_t sizeOfElement ); There’s one major difference and one minor difference between the two functions. The major difference is that malloc() doesn’t initialize the allocated memory. The first time malloc() gives you a particular chunk of memory, the memory might be full of zeros. If memory has been allocated, freed, and reallocated, it probably has whatever junk was left in it. That means, unfortunately, that a program might run in simple cases (when memory is never reallocated) but break when used harder (and when memory is reused). calloc() fills the allocated memory with all zero bits. That means that anything there you’re going to use as a char or an int of any length, signed or unsigned, is guaranteed to be zero. Anything you’re going to use as a pointer is set to all zero bits. That’s usually a null pointer, but it’s not guaranteed.Anything you’re going to use as a float or double is set to all zero bits; that’s a floating-point zero on some types of machines, but not on all. The minor difference between the two is that calloc() returns an array of objects; malloc() returns one object. Some people use calloc() to make clear that they want an array.

Question - 135 : - What is modular programming?

Answer - 135 : - 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.

Question - 136 : - printf() Function- What is the difference between "printf(...)" and "sprintf(...)"?

Answer - 136 : - sprintf(...) writes data to the character array whereas printf(...) writes data to the standard output device.

Question - 137 : - What will be printed as the result of the operation below: main() { int x=5; printf(“%d,%d,%d\n”,x,x<<2,>>2) ; }

Answer - 137 : - 5,20,1

Question - 138 : - How do you print only part of a string?

Answer - 138 : - /* Use printf() to print the first 11 characters of source_str. */ printf(First 11 characters: ‘%11.11s’n, source_str);

Question - 139 : - What is the purpose of main( ) function?

Answer - 139 : - The function main( ) invokes other functions within it.It is the first function to be called when the program starts execution. - It is the starting function - It returns an int value to the environment that called the program - Recursive call is allowed for main( ) also. - It is a user-defined function - Program execution ends when the closing brace of the function main( ) is reached. - It has two arguments 1)argument count and 2) argument vector (represents strings passed). - Any user-defined name can also be used as parameters for main( ) instead of argc and argv

Question - 140 : - Are pointers integers?

Answer - 140 : - No, pointers are not integers. A pointer is an address. It is merely a positive number and not an integer.

Computer Contributors

Rajeev Katiyar
Yes Baroda

Share your email for latest updates


Our partners