C Questions only (6)
C Interview Questions and Answers
(Continued from previous question...)
C Questions only (6)
49.
Sample Code
int my_func( int *a );
int main()
{
int b[3];
my_func( ???? );
return 0;
}
Referring to the sample code above, which one of the following must be inserted in place of the ???? to pass the array b to my_func?
1 (int *)b[0]
2 b
3 (int *)*b
4 (*b)[0]
5 *b
50.
Sample Code
void printTime( time_t *t )
{
????
}
Which one of the following can replace the ???? in the code above to print the time passed in t in human-readable form?
1 char s[ 100 ];
ctime( t, s );
printf( "%s\n", s );
2 printf( "%s\n", ctime( t ) );
3 printf( "%s\n", asctime( t ) );
4 printf( "%s", t );
5 char *s = ctime( t );
printf( "%s\n", s );
free( s );
51.
How do you declare a constant pointer to a constant string?
1 const* char const p;
2 const const char* p;
3 char const const* p;
4 const char const* p;
5 const char* const p;
52.
Sample Code
#include
int ab=1;
int a=2;
int main(){
int b=3;
int ab=4;
printf("%i/*%i*/%i",a,b,ab);
}
Refer to the above sample code. What will be printed?
1 21
2 0/*4*/1
3 01
4 %i/*%i*/%i041
5 2/*3*/4
53.
Sample Code
int z;
int x = 5;
int y = -10;
int a = 4;
int b = 2;
z = x++ + ++y * b / a;
What number will z in the sample code above contain?
1 -3
2 -2
3 0
4 1
5 2
54.
Which one of the following functions allows an existing stream to be redirected?
1 setvbuf()
2 dup()
3 fopen()
4 popen()
5 freopen()
55.
Sample Code
int x = 0;
for ( ; ; )
{
if (x++ == 4) break;
continue;
}
printf("x=%d\n", x);
What will be printed when the sample code above is executed?
1 x=0
2 x=1
3 x=4
4 x=5
5 x=6
56.
Sample Code
/* Eliminate all whitespace from the end of s. */
void rtrim (char * s) {
char * start, ws, text;
start = s, ws = text = s - 1;
while (*s != '\0') {
if (isspace(*s)) {
ws = s;
while (isspace(*s)) s++;
} else {
text = s;
while (*s != '\0' && !isspace(*s)) s++;
}
}
if (ws > text) *ws = '\0';
}
The function rtrim(), defined above, contains an implementation error. Which one of the following describes it?
1 The comma operator has a higher precedence than assignment; this produces an unintended effect.
2 rtrim() does not correctly handle the case where no character of s is whitespace.
3 rtrim() does not correctly handle the case where every character of s is whitespace.
4 ws and text are not assignment-compatible with s or NULL.
5 The loop and its subordinate statements do not adequately detect an end-of-string condition on s in all cases.
57.
Sample Code
struct customer *ptr = malloc( sizeof( struct customer ) );
Given the sample allocation for the pointer "ptr" found above, which one of the following statements is used to reallocate ptr to be an array of 10 elements?
1 ptr = realloc( ptr, 10 * sizeof( struct customer ) );
2 realloc( ptr, 10 * sizeof( struct customer ) );
3 realloc( ptr, 9 * sizeof( struct customer ) );
4 ptr += malloc( 9 * sizeof( struct customer ) );
5 ptr = realloc( ptr, 9 * sizeof( struct customer ) );
(Continued on next question...)
Other Interview Questions
|