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

}
The function func(), triggers memory fault. Which one explains why "func" may NOT be printed before the crash?
Choice 1
Insufficient information to determine why the output fails.

Choice 2
printf() expects more than one argument. As only one argument is given, crash may actually occur inside printf().

Choice 3
Output stream is buffered and may not be flushed before the crash occurs. (Ans--?)

Choice 4
printf() always buffers output until a newline character appears in buffer. Since no newline was present in the format string, nothing is printed.
0
MultipleChoiceInC's Avatar
Go4Expert Member
How does variable definition differ from variable declaration?

Choice 1
Definition allocates storage for a variable, but declaration only informs the compiler as to the variable's type.

Choice 2
Declaration allocates storage for a variable, but definition only informs the compiler as to the variable's type.

Choice 3
Variables may be defined many times, but may be declared only once.(Ans --?)

Choice 4
Variable definition must precede variable declaration.

Choice 5
There is no difference in C between variable declaration and variable definition.
0
MultipleChoiceInC's Avatar
Go4Expert Member
Which one of the following is a true statement about pointers?

Choice 1
Pointer arithmetic is permitted on pointers of any type.(Ans-- ??)

Choice 2
A pointer of type void * can be used to directly examine or modify an object of any type.

Choice 3
Standard C mandates a minimum of four levels of indirection accessible through a pointer.

Choice 4
A C program knows the types of its pointers and indirectly referenced data items at runtime.

Choice 5
Pointers may be used to simulate call-by-reference.
0
MultipleChoiceInC's Avatar
Go4Expert Member
unsigned int p=0;
(p^p)||p++||++p||p++;

What is the value of the variable "p" after executing the above code?

Choice 1
1

Choice 2
2 (Ans--??)

Choice 3
3

Choice 4
The value is undefined because "p" is initialized to 0.
0
MultipleChoiceInC's Avatar
Go4Expert Member
Which is functionally equivalent of arithmetic right shift of signed int p by 2 and is portable?

Choice 1
p / 4 (Ans---??)

Choice 2
p / 2

Choice 3
p >>> 2

Choice 4
p >> 2

Choice 5
p > 0 ? p >> 2 | 1 << sizeof(p) * 8 - 1 : p >> 2
0
MultipleChoiceInC's Avatar
Go4Expert Member
char var1[10];
char var2[5]="Forum";
strcpy(var1,var2);
printf("%s,%s",var1,var2);
What is the output of the above code?

Choice 1
No output as it is array overflow error.

Choice 2
"Forum Forum"

Choice 3
Results undefined. Depending on platform, code may cause access violation.

Choice 4
Compilation error because string pointers can be initialized with a string literals only
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.