Part2 – Interview Questions - Interview Questions
- -3 : 4, -4 : 3 [Ans]
- -4 : 4, -3 : 3
- -4 : 3, -4 : 3
- -4 : 3, -3 : 4
- -3 : 3, -4 : 4
- int *x;
*x = 0×200;[Ans] - int *x = &0×200;
- int *x = *0×200;
- int *x = 0×200;
- int *x( &0×200 );
- 4
- 5
- 6 [Ans]
- 7
- 8
- 0
- 1
- 2[Ans]
- 3
- 4
- char ** (* p) [12][12] = array; [Ans]
- char ***** p = array;
- char * (* p) [12][12][12] = array;
- const char ** p [12][12][12] = array;
- char (** p) [12][12] = array;
- typedef void (*sighandler_t) (int);[Ans]
- typedef sighandler_t void (*) (int);
- typedef void *sighandler_t (int);
- #define sighandler_t(x) void (*x) (int)
- #define sighandler_t void (*) (int)
- int count_digits (const char * buf) {
assert(buf != NULL);
int cnt = 0, i;
for (i = 0; buf[i] != ‘\0′; i++)
if (isdigit(buf[i]))
cnt++;
return cnt;
} - int count_digits (const char * buf) {
int cnt = 0;
assert(buf != NULL);
for (int i = 0; buf[i] != ‘\0′; i++)
if (isdigit(buf[i]))
cnt++;
return cnt;
} - int count_digits (const char * buf) {
int cnt = 0, i;
assert(buf != NULL);
for (i = 0; buf[i] != ‘\0′; i++)
if (isdigit(buf[i]))
cnt++;
return cnt;
} - int count_digits (const char * buf) {
assert(buf != NULL);
for (i = 0; buf[i] != ‘\0′; i++)
if (isdigit(buf[i]))
cnt++;
return cnt;
} - int count_digits (const char * buf) {
assert(buf != NULL);
int cnt = 0;
for (int i = 0; buf[i] != ‘\0′; i++)
if (isdigit(buf[i]))
cnt++;
return cnt;
} - ptr = realloc( ptr, 10 * sizeof( struct customer)); [Ans]
- realloc( ptr, 9 * sizeof( struct customer ) );
- ptr += malloc( 9 * sizeof( struct customer ) );
- ptr = realloc( ptr, 9 * sizeof( struct customer ) );
- realloc( ptr, 10 * sizeof( struct customer ) );
- Pointer arithmetic is permitted on pointers of any type.
- A pointer of type void * can be used to directly examine or modify an object of any type.
- Standard C mandates a minimum of four levels of indirection accessible through a pointer.
- A C program knows the types of its pointers and indirectly referenced data items at runtime.
- Pointers may be used to simulate call-by-reference.
- localtime
- gmtime
- strtime
- asctime
- ctime
- It will not compile because not enough initializers are given.
- 6
- 7
- 12
- 24 [Ans]
- The first definition certainly allows the contents of buf to be safely modified at runtime; the second definition does not.
- The first definition is not suitable for usage as an argument to a function call; the second definition is.
- The first definition is not legal because it does not indicate the size of the array to be allocated; the second definition is legal.
- They do not differ — they are functionally equivalent. [Ans]
- The first definition does not allocate enough space for a terminating NUL-character, nor does it append one; the second definition does.
- @@
- ||
- .AND.
- && [Ans]
- AND
- %e always displays an argument of type double in engineering notation; %f always displays an argument of type double in decimal notation. [Ans]
- %e expects a corresponding argument of type double; %f expects a corresponding argument of type float.
- %e displays a double in engineering notation if the number is very small or very large. Otherwise, it behaves like %f and displays the number in decimal notation.
- %e displays an argument of type double with trailing zeros; %f never displays trailing zeros.
- %e and %f both expect a corresponding argument of type double and format it identically. %e is left over from K&R C; Standard C prefers %f for new.
- clearerr()
- fseek()
- ferror()
- feof()
- setvbuf()
- c = getc();
- getc( &c );
- c = getchar( stdin );
- getchar( &c )
- c = getchar(); [Ans]
- It will not compile.
- It will print out: i=9.
- It will print out: i=10.
- It will print out: i=11.
- It will loop indefinitely.[Ans]
- There will be a memory overwrite.
- There will be a memory leak.
- There will be a segmentation fault.
- Not enough space is allocated by the malloc.
- It will not compile.
- i = 5[Ans]
- i = 8
- i = 9
- i = 10
- i = 18
- = [Ans]
- ,
- []
- ^
- ->
- It automatically initializes a variable to 0;.
- It indicates that a variable's memory will automatically be preserved.[Ans]
- It automatically increments the variable when used.
- It automatically initializes a variable to NULL.
- It indicates that a variable's memory space is allocated upon entry into the block.
- #include
[Ans] - #incl "sysheader.h"
- #includefile
- #include sysheader.h
- #incl
- %-30.4e
- %4.30e
- %-4.30f
- %-30.4f [Ans] decimal notation
- %#30.4f
- x=0
- x=1
- x=4
- x=5[Ans]
- x=6
- 1, 2, 2
- 1, 2, 4
- 1, 2, 8
- 2, 2, 4[Ans]
- 2, 4, 8
- 6
- 7
- 8
- 9[Ans]
- The will not compile.
- enum coin {(penny,1), (nickel,5), (dime,10), (quarter,25)};
- enum coin ({penny,1}, {nickel,5}, {dime,10}, {quarter,25});
- enum coin {penny=1,nickel=5,dime=10,quarter=25};[Ans]
- enum coin (penny=1,nickel=5,dime=10,quarter=25);
- enum coin {penny, nickel, dime, quarter} (1, 5, 10, 25);
- 11 bytes
- 12 bytes
- 13 bytes
- 20 bytes[Ans]
- 21 bytes
- z=0.00
- z=1.00[Ans]
- z=1.50
- z=2.00
- z=NULL
- go_cart
- go4it
- 4season[Ans]
- run4
- _what
- Standard C defines this particular behavior as implementation-dependent. The compiler writer has the freedom to decide how the remaining elements will be handled.
- The remaining elements are initialized to zero(0).[Ans]
- It is illegal to initialize only a portion of the array. Either the entire array must be initialized, or no part of it may be initialized.
- As with an enum, the compiler assigns values to the remaining elements by counting up from the last explicitly initialized element. The final four elements will acquire the values 4, 5, 6, and 7, respectively.
- They are left in an uninitialized state; their values cannot be relied upon.
- They are always 32-bit values.
- For efficiency, pointer values are always stored in machine registers.
- With the exception of generic pointers, similarly typed pointers may be subtracted from each other.
- A pointer to one type may not be cast to a pointer to any other type.
- With the exception of generic pointers, similarly typed pointers may be added to each other.
- int *ptr = (int *) malloc(10, sizeof(int));
- int *ptr = (int *) calloc(10, sizeof(int));
- int *ptr = (int *) malloc(10*sizeof(int)); [Ans]
- int *ptr = (int *) alloc(10*sizeof(int));
- int *ptr = (int *) calloc(10*sizeof(int));
- stdout and stderr
- console and error
- stdout and stdio
- stdio and stderr
- errout and conout
- X() effectively rounds f to the nearest integer value, which it returns.
- X() effectively performs a standard typecast and converts f to a roughly equivalent integer.
- X() preserves the bit-pattern of f, which it returns as an unsigned integer of equal size.
- Since u.n is never initialized, X() returns an undefined value. This function is therefore a primitive pseudorandom number generator.
- Since u.n is automatically initialized to zero (0) by the compiler, X() is an obtuse way of always obtaining a zero (0) value.
- if (x == 0) return 0;
- return 1;
- if (x >= 2) return 2;
- if (x == 0) return 1;
- if (x <= 1) return 1; [Ans]{more probable}
- *p++ causes p to be incremented before the dereference is performed, because both operators have equal precedence and are right associative.
- An array is a nonmodifiable lvalue, so p cannot be incremented directly. A navigation pointer should be used in conjunction with p.
- *p++ causes p to be incremented before the dereference is performed, because the autoincrement operator has higher precedence than the indirection operator.
- The condition of a while loop must be a Boolean expression. The condition should be n != 0.
- An array cannot be initialized to a variable size. The subscript n should be removed from the definition of the parameter p.
- The global variable is referenced via the extern specifier.[Ans]
- The global variable is referenced via the auto specifier.
- The global variable is referenced via the global specifier.
- The global variable is referenced via the pointer specifier.
- The global variable is referenced via the ext specifier.
- The variable's value
- The variable's binary form
- The variable's address [Ans]
- The variable's format
- The variable's right value
- The __P() macro has no function, and merely obfuscates library function declarations. It should be removed from further releases of the C library.
- The __P() macro provides forward compatibility for C++ compilers, which do not recognize Standard C prototypes.
- Identifiers that begin with two underscores are reserved for C library implementations. It is impossible to determine the purpose of the macro from the context given.
- The __P() macro provides backward compatibility for K&R C compilers, which do not recognize Standard C prototypes.
- The __P() macro serves primarily to differentiate library functions from application-specific functions.
- __ident
- auto [Ans]
- bigNumber
- g42277
- peaceful_in_space
What will the below print when executed?
double x = -3.5, y = 3.5;
printf( "%.0f : %.0f\n", ceil( x ), ceil( y ) );
printf( "%.0f : %.0f\n", floor( x ), floor( y ) );
ceil =>rounds up 3.2=4 floor =>rounds down 3.2=3
Which one of the following will declare a pointer to an integer at address 0×200 in memory?
After the sample below has been executed, what value will the variable x contain?
int x = 5;
int y = 2;
char op = '*';
switch (op)
{
default : x += 1;
case '+' : x += y; It will go to all the cases
case '-' : x -= y;
}
Referring to the sample below, what value will the variable counter have when completed?
x = 3, counter = 0;
while ((x-1))
{
++counter;
x--;
}
Consider array, defined below. Which one of the following definitions and initializations of p is valid?
char ** array [12][12][12];
Which one of the following definitions of sighandler_t allows the below declaration to be rewritten as follows:
sighandler_t signal (int sig, sighandler_t handler);
void (*signal(int sig, void (*handler) (int))) (int);
All of the following choices represent syntactically correct function definitions. Which one of the following represents a semantically legal function definition in Standard C?
Given the sample allocation for the pointer “ptr” found below, which one of the following statements is used to reallocate ptr to be an array of 10 elements?
struct customer *ptr = malloc( sizeof( struct customer ) );
Which one of the following is a true statement about pointers?
Which one of the following functions returns the string representation from a pointer to a time_t value?
Assuming a short is two bytes long, what will be printed by the below?
short testarray[4][3] = { {1}, {2, 3}, {4, 5, 6} };
printf( "%d\n", sizeof( testarray ) );
In terms of generation, how do the two definitions of buf, both presented below, differ?
char buf [] = "Hello world!";
char * buf = "Hello world!";
In a C expression, how is a logical AND represented?
How do printf()’s format specifiers %e and %f differ in their treatment of floating-point numbers?
Which one of the following Standard C functions can be used to reset end-of-file and error conditions on an open stream?
Which one of the following will read a character from the keyboard and will store it in the variable c?
What will happen when the program below is compiled and executed?
#include
int i;
void increment( int i )
{
i++;
}
int main()
{
for( i = 0; i < 10; increment( i ) )
{
}
printf("i=%d\n", i);
return 0;
}
What is wrong with the below(assuming the call to malloc does not fail)?
char ptr1[] = "Hello World";
char *ptr2 = malloc( 5 );
ptr2 = ptr1;
What will the output of the sample below be?
int i = 4;
switch (i)
{
default:
;
case 3:
i += 5;
if ( i == 8 )
{
i++;
if (i == 9) break;
i *= 2;
}
i -= 4;
break;
case 8:
i += 5;
break;
}
printf("i = %d\n", i);
Which one of the following C operators is right associative?
What does the "auto" specifier do?
How do you include a system header file called sysheader.h in a C source file?
Which one of the following printf() format specifiers indicates to print a double value in decimal notation, left aligned in a 30-character field, to four (4) digits of precision?
What will be printed when the sample below is executed?
int x = 0;
for ( ; ; )
{
if (x++ == 4)
break;
continue;
}
printf("x=%d\n", x);
According to the Standard C specification, what are the respective minimum sizes (in bytes) of the following three data types: short; int; and long?
What is printed when the sample below is executed?
int y[4] = {6, 7, 8, 9};
int *ptr = y + 2;
printf("%d\n", ptr[ 1 ] ); ptr+1 == ptr[1]
How is enum used to define the values of the American coins listed below?
penny = one
nickel = five
dime = ten
quarter = twenty-five
How many bytes are allocated by the definition below?
char txt [20] = "Hello world!\0";
What will print when the sample below is executed?
int i = 4;
int x = 6;
double z;
z = x / i;
printf("z=%.2f\n", z);
Which one of the following variable names is NOT valid?
The definition of a below explicitly initializes its first four elements. Which one of the following describes how the compiler treats the remaining four elements?
int a [8] = { 0, 1, 2, 3 };
Which one of the following is a true statement about pointers?
Which one of the following statements allocates enough space to hold an array of 10 integers that are initialized to 0?
What are two predefined FILE pointers in C?
Given the function X(), defined below, assume that u32 is a type-definition indicative of a 32-bit unsigned integer and that f32 is a type-definition indicative of a 32-bit floating-point number.Which one of the following describes the purpose of the function defined below?
u32 X (f32 f)
{
union {
f32 f;
u32 n;
} u;
u.f = f;
return u.n;
}
With what do you replace the ???? to make the function shown below return the correct answer?
long factorial (long x)
{
????
return x * factorial(x - 1);
}
Consider the function increment_ints(), defined below. Despite its significant inline commentary, it contains an error. Which one of the following correctly assesses it?
Increment each integer in the array 'p' of * size 'n'.
void increment_ints (int p [n], int n)
{
assert(p != NULL); Ensure that 'p' isn't a null pointer.
assert(n >= 0); Ensure that 'n' is nonnegative.
while (n) Loop over 'n' elements of 'p'.
{
*p++; Increment *p.
p++, n--; Increment p, decrement n.
}
}
How is a variable accessed from another file?
When applied to a variable, what does the unary "&" operator yield?
The below comes from header files for the FreeBSD implementation of the C library. What is the primary purpose of the __P() macro?
sys/cdef.h
#if defined(__STDC__) || defined(__cplusplus)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
stdio.h
#include
div_t div __P((int, int));
Which one of the following is NOT a valid identifier?