◆假定在所有的程序中必须的头文件都已经被正确包含。
考虑如下的数据类型: ◆char为1个字节 1、Consider the following program:
(a) 3 (b) 5 (c) 0 (d) None of the above 2、Consider the following program:
(a) 3 (b) 5 (c) 6 (d) 7 3、Consider the following code segment:
What function of x and n is compute by this code segment? 4、Consider the following program:
(a) 2 2 (b) 2 1 (c) 2 5 (d) None of the above 5、Consider the following program:
(a) 8 (b) 9 (c) 7 (d) None of the above 6、Consider the following program:
(a) c=3 d=3 (b) c=5 d=3 (c) c=3 d=5 (d) c=5 d=5 7、Consider the following program:
(a) 2 3 5 6 (b) 2 3 4 5 (c) 4 5 0 0 (d) None of the above 8、Consider following function:
(a) Only f3 (b) Only f1 and f3 (c) Only f1 and f2 (d) f1 , f2 ,f3 9、Consider the following program:
The output for this program is: 10、Consider the following program:
(a) 5 5 5 5 (b) 3 5 3 5 (c) 5 3 5 3 (d) 3 3 3 3 11、Consider the following program:
(a) 0 1 2 0 (b) 0 1 2 1 (c) 1 2 0 1 (d) 0 2 1 1 12、Consider following declaration
(a) Pointer to function of having two arguments that is pointer to float (b) int (c) Pointer to function having two argument that is pointer to float and return int (d) None of the above 13、Consider the following program:
(a) 5 (b) 6 (c) 9 (d) None of the above 14、Consider the following program:
(a) ab (b) cd (c) ef (d) gh 15、Consider the following program:
(a) 7 (b) 6 (c) 5 (d) 3 16、Consider the following program:
(a) 10 (b) 15 (c) 6 (d) 7 Answer With Detailed Explanation Answer 1. volatile variable isn't affected by the optimization. Its value after the longjump is the last value variable assumed. b last value is 5 hence 5 is printed. setjmp : Sets up for nonlocal goto /* setjmp.h*/ Stores context information such as register values so that the lomgjmp function can return control to the statement following the one calling setjmp.Returns 0 when it is initially called. Lonjjmp:longjmp Performs nonlocal goto /* setjmp.h*/ Transfers control to the statement where the call to setjmp (which initialized buf) was made. Execution continues at this point as if longjmp cannot return the value 0.A nonvolatile automatic variable might be changed by a call to longjmp.When you use setjmp and longjmp, the only automatic variables guaranteed to remain valid are those declared volatile. Note: Test program without volatile qualifier (result may very) Answer 2. The members of structures have address in increasing order of their declaration. If a pointer to a structure is cast to the type of a pointer to its first member, the result refers to the first member. Answer 3. Non recursive version of the program
Algorithm description
The answer is (c) type of a is array of int Answer 5. Answer 6. The comma separates the elements of a function argument list. The comma is also used as an operator in comma expressions. Mixing the two uses of comma is legal, but you must use parentheses to distinguish them. the left operand E1 is evaluated as a void expression, then E2 is evaluated to give the result and type of the comma expression. By recursion, the expression E1, E2, ..., En results in the left-to-right evaluation of each Ei, with the value and type of En giving the result of the whole expression.
The answer is (a) /* ptr is pointer to array of 3 int */ Answer 8. f1 and f2 return address of local variable ,when function exit local variable disappeared Answer 9. sizeof operator gives the number of bytes required to store an object of the type of its operand . The operands is either an expression, which is not evaluated ( (++i + ++ i ) is not evaluated so i remain 3 and j is sizeof int that is 2) or a parenthesized type name. Answer 10. void(*p[2]) ( int *, int); Answer 11. Answer 12. C provide a facility called typedef for creating new data type names, for example declaration
Makes the name string a synonym for int .The type string can be used in declaration, cast, etc, exactly the same way that the type int can be. Notice that the type being declared in a typedef appears in the position of a variable name not after the word typedef. Answer 13. If the type of an expression is "array of T" for some type T, then the value of the expression is a pointer to the first object in the array, and the type of the expression is altered to "pointer to T" So (buf+1)[5] is equvalent to *(buf +6) or buf[6] Answer 14. p+=sizeof(int) point to argv[2] Answer 15. When we call ripple value of the first argument passed to ripple is collected in the n that is 3. va_start initialize p to point to first unnamed argument that is 5 (first argument).Each call of va_arg return an argument and step p to the next argument. va_arg uses a type name to determine what type to return and how big a step to take Consider inner loop
in five number of 1 bits is (101) 2 example
The right most 1 bit of i has corresponding 0 bit in i-1 this way i & i-1, in a two complement number system will delete the right most 1 bit I(repeat until I become 0 gives number of 1 bits) Answer 16. Static variable count remain in existence rather than coming and going each time function is called |