a) ptr = ptr + sizeof(myStruct); [Ans]
b) ++(int*)ptr;
c) ptr = ptr + sizeof(myArray);
d) increment(ptr);
e) ptr = ptr + sizeof(ptr);
Showing posts with label pointers. Show all posts
Showing posts with label pointers. Show all posts
Wednesday, February 10, 2010
Sunday, January 10, 2010
Which one of the following statements could replace the ???? in the code above to cause the string 1-2-3-10-5- to be printed when the code is executed?
int x[] = {1, 2, 3, 4, 5};
int u;
int *ptr = x;
????
for( u = 0; u < 5; u++ ) { printf("%d-", x[u]); } printf( "\n" ); a) *ptr + 3 = 10; b) *ptr[ 3 ] = 10; c) *(ptr + 3) = 10; d) (*ptr)[ 3 ] = 10; e) *(ptr[ 3 ]) = 10;
int u;
int *ptr = x;
????
for( u = 0; u < 5; u++ ) { printf("%d-", x[u]); } printf( "\n" ); a) *ptr + 3 = 10; b) *ptr[ 3 ] = 10; c) *(ptr + 3) = 10; d) (*ptr)[ 3 ] = 10; e) *(ptr[ 3 ]) = 10;
In terms of code generation, how do the two definitions of buf, both presented above, differ?
char buf [] = "Hello world!";
char * buf = "Hello world!";
a) The first definition certainly allows the contents of buf to be safely modified at runtime; the second definition does not
b) The first definition is not suitable for usage as an argument to a function call; the second definition is
c) The first definition is not legal because it does not indicate the size of the array to be allocated; the second definition is legal
d) They do not differ -- they are functionally equivalent
e) The first definition does not allocate enough space for a terminating NUL-character, nor does it append one; the second definition does
char * buf = "Hello world!";
a) The first definition certainly allows the contents of buf to be safely modified at runtime; the second definition does not
b) The first definition is not suitable for usage as an argument to a function call; the second definition is
c) The first definition is not legal because it does not indicate the size of the array to be allocated; the second definition is legal
d) They do not differ -- they are functionally equivalent
e) The first definition does not allocate enough space for a terminating NUL-character, nor does it append one; the second definition does
Which one of the following will declare a pointer to an integer at address 0x200 in memory?
a) int *x;
*x = 0x200;
b) int *x = &0x200;
c) int *x = *0x200;
d) int *x = 0x200;
e) int *x( &0x200 );
*x = 0x200;
b) int *x = &0x200;
c) int *x = *0x200;
d) int *x = 0x200;
e) int *x( &0x200 );
Thursday, April 9, 2009
What is the ANSI Standard definition of a null pointer constant?
Answer: "An integral constant expression with the value 0, or such an expression cast to type (void *)".
Wednesday, February 11, 2009
Why does a pointer definition need a type to be specified?
Choice a : To specify the size of the pointer
Choice b : To clear the memory being pointed to before it is assigned
Choice c : To set the endianness of the pointer
Choice d : To set the address space definition
Choice e : To allow pointer math to work properly
Choice b : To clear the memory being pointed to before it is assigned
Choice c : To set the endianness of the pointer
Choice d : To set the address space definition
Choice e : To allow pointer math to work properly
If a machine uses some nonzero internal bit pattern for null pointers, how should the NULL macro be defined?
Answer: As 0 (or (char *)0), as usual. The *compiler* is responsible for translating null pointer constants into internal null pointer representations, not the
preprocessor.
preprocessor.
Subscribe to:
Posts (Atom)