0
MultipleChoiceInC's Avatar
Go4Expert Member
void crash(void){
printf("got there");
((char*) 0)=0;

}
The function crash(), defined above, triggers a fault in the memory management hardware for many architectures. Which one of the following explains why "got here" may NOT be printed before the crash?
Choice 1

There is insufficient information to determine why the output fails to appear. A broader context is required.
Choice 2

printf() expects more than a single argument. Since only one argument is given, the crash may actually occur inside printf(), which explains why the string is not printed. puts() should be used instead.
Choice 3

If the standard output stream is buffered, the library buffers may not be flushed before the crash occurs. (Ans--?)
Choice 4

printf() always buffers output until a newline character appears in the buffer. Since no newline was present in the format string, nothing is printed.
0
MultipleChoiceInC's Avatar
Go4Expert Member
What is a variable DECLARATION (as opposed to a variable definition)?
Choice 1

The assignment of properties and an identifier (a name) to a variable (Ans---?)
Choice 2

The assignment of storage space to a variable
Choice 3

The assignment of properties and storage space to a variable
0
MultipleChoiceInC's Avatar
Go4Expert Member
Which one of the following is true about null pointers?
Choice 1

The null pointer is a pointer to a string of zero (0) width; that is, it is a pointer to the NUL character.
Choice 2

The null pointer is the pointer in which the value is zero (0).
Choice 3

The null pointer is any uninitialized pointer.
Choice 4

The null pointer is the pointer in which the value is the value of a constant defined several places throughout the standard library. ()
Choice 5

The null pointer is known to point to no object and is represented in C expressions by a pointer-typed zero (0). (Ans--?)
0
MultipleChoiceInC's Avatar
Go4Expert Member
unsigned int x=0;
(x^x)||x++||++x||x++;

What is the value of "x" after the execution of the above sample code?
Choice 1

1
Choice 2

2 (Ans--??)
Choice 3

3
Choice 4

The value is undefined because "x" is initialized to 0.
0
MultipleChoiceInC's Avatar
Go4Expert Member
A right shift is arithmetic if it propagates the sign bit of its principal operand. The C standard grants compiler writers the freedom to determine whether or not right shifts should be arithmetic. Given the definition above, which one of the following is functionally equivalent to an arithmetic right shift of signed int x by two (2) and is guaranteed to be portable?
Choice 1

x / 4 (Ans---??)
Choice 2

x / 2
Choice 3

x >>> 2
Choice 4

x >> 2
Choice 5

x > 0 ? x >> 2 | 1 << sizeof(x) * 8 - 1 : x >> 2
0
MultipleChoiceInC's Avatar
Go4Expert Member
char var1[10];
char var2[5]="hello";
strcpy(var1,var2);
printf("%s,%s",var1,var2);

What does the above code print?
Choice 1

Nothing, the link fails with an array overflow error.
Choice 2

"Hello Hello"
Choice 3

It is unknown; the results are undefined, and depending on the platform, the code may cause an access violation or core dump.
Choice 4

Nothing, the compilation fails, because only string pointers can be initialized with a string literal.
Choice 5

Nothing, the program fails with an "array overflow" runtime error message before printing anything.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by MultipleChoiceInC
int main(void){free(0)}

Which one of the following statements is true regarding the above code in Standard C?
Choice 1

The freeing of a null pointer will cause a program crash.
Choice 2

The code is wrong because free is not a standard C function.
Choice 3

malloc should be called before free.
Choice 4

The code is wrong because free does not take one argument.
Choice 5

The call to free will have no effect. (Ans-???)
The freeing of a null pointer will cause a program crash.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by MultipleChoiceInC
New Question:

double d[128];

Considering the definition of d above, which one of the following code fragments portably writes the contents of the array d to the stream indicated by fp in native representation?
Choice 1

fprintf(fp, "%[128d", d);
Choice 2

fwrite(d, sizeof(double), sizeof(d), fp);
Choice 3

fwrite(d, sizeof(d), sizeof(double), fp);
Choice 4

write(fp, d, sizeof(d));
Choice 5

fwrite(d, sizeof(*d), 128, fp);
Checkout the function signature and that would help
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by MultipleChoiceInC
Which one of the following appends the character '?' to the string str ?
Choice 1

strcat(str,"\?"); (Ans--?)
Choice 2

strccat(str,'?');
Choice 3

strapp(str,'?');
Choice 4

strcat(str,'?');
Choice 5

strcon(str,"?");
strcat(str,"\?");
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by MultipleChoiceInC
Which one of the following is a true statement about an lvalue?
Choice 1

An lvalue is, by definition, the value appearing on the rightmost side of an assignment statement.
Choice 2

By definition, an lvalue is the storage space indirectly referenced by a pointer.
Choice 3

All lvalues can be used on the right side of an assignment statement. (Ans--?)
Choice 4

An lvalue is the result of an arithmetic operation involving quantities of type long int.
By definition, an lvalue is the storage space indirectly referenced by a pointer.