ANSI C Programming: Pointers

Which of the following are benefits of pointers?

Pointers can be defined for any simple or complex data object that can be defined in ANSI C
Pointers are more efficient than array subscripting for operations with complex datatypes
No memory is allocated to pointers other than the memory required to store addresses
If pointers to different datatypes are defined, the internal implementation of the pointers is the same for each type
1, 2, 3
Which of the following statements will initialize a character pointer *cptr to a character variable cval?
%010cptr = &cval
%010cptr = *cval;
%010cptr = cval
%010cptr = &cval;

4
Which of the following statements defines a character pointer called cptr?

%010char cptr;
%010char *cptr
%010char *cptr;
%010char &cptr

3
Which of the following statements initializes a character pointer cptr to the array carr?

Cptr = &carr;
Cptr = carr;
Cptr = carr
Cptr = *carr;

2
By what is a function called when the address of a data object is passed as a parameter to a function?

Return value
Reference
Value
2
Which of the following lines of code will pass a pointer called ip to a function called changei?
%010changei(*ip);
%010changei(&ip);
%010changei(ip);
%010changei(*ip)
3
Which of the following lines of code will pass the address of a structure called element to a function change_struct()?

%010change_struct(element);
%010change_struct(&element);
%010change_struct(&element)
%010change_struct(element)
2

Which of the following statements about call by reference is true?
It is usually more efficient than call by value
It copies the parameter data to the called function
If the called function changes the data, the change is not reflected in the calling function
1

In general, what is the maximum number of levels of indirection you should go to in ANSI C?

Two
Three
Four
Five

1

Which of the following pieces of code will act as a header for a function named change_str(), which contains a pointer cptr that points to a character pointer?
%010change_str(char *cptr)
%010change_str(char **cptr);
%010change_str(char **cptr)
%010change_str(char ->cptr)

3

Which of the following lines of code will pass the address of a pointer *cp to a function change_str()?
%010change_str(&cp);
%010change_str(cp)
%010change_str(*cp);
%010change_str(&cp)

1
If an element in an array is a space, which of the following will happen?

The space will be replaced with a new line character
The final space in the array will be deleted
The position of the pointer that cptr points to will be recorded
The space will be replaced with a pointer

1, 3

Which of the following statements will increment a pointer ptr so that it points to the next element in an array?

%010ptr++
*ptr++
%010ptr++;
*ptr++;

3
Which of the following statements will increment a pointer iptr by four?

(*(++iptr));
%010iptr += 4;
%010iptr = iptr+4;
(*(++iptr)++)

2, 3

What does the statement *iptr++; require the program to get at iptr before incrementing the pointer by one?
The value
The pointer
The data object
3

Which of the following statements defines a pointer fptr to a function?
%010int *fptr();
%010int (*fptr)();
%010int *fptr [];
%010int (*fptr)[];
2

Which of the following lines of code defines an array of four pointers to functions that return integers?
%010int (*fptr)();
%010int (*fptr(4))();
%010int (*fptr[4])();
%010int *fptr[4]();
|
3

What do you list between delimiters to initialize an array of pointers to functions?

Function names
Function prototypes
Function pointers
|
1

Which of the following statements call the function drawline(), passing the value 200 as a parameter?

(fptr)(200);
(200)(*fptr);
(*fptr)(200);
(*fptr,200);
1, 3

Which of the following statements defines an array cptr of five pointers, where each element is a character pointer?
%010char cptr[5]
%010char *cptr[5];
%010char *cptr[5]
%010char cptr[5];
|
2
Which of the following is a true statement about defining an array of pointers in ANSI C?
It is possible to define an array of pointers to character pointers only
It is possible to define an array of pointers to integer pointers only
It is possible to define an array of pointers to any data type
|
3
The pointer spp is a pointer to an array of pointers, each of which points to a structure struct stock_type.
Which of the following statements will access a member of a structure struct stock_type called stock_num?

*spp->stock_num
(*spp)->stock_num
(**spp).stock_num
(*spp)**stock_num

2, 3

In the code given, which of the following lines of code initializes the pointer cpp to the cptr array?

char *cptr[10];
char **cpp;

%010cpp = cptr;
**cpp = cptr;
*cpp = cptr;
%010cpp = *cptr;
|
1

Which of the following functions are contained as prototypes in the stdlib.h file?
%010malloc()
%010free()
%010realloc()
%010gets()
|
1, 2, 3

Which of the following statements are true?

The realloc() function changes the size of the memory allocated to some specified size
The calloc() function is similar to malloc(), except that it returns a pointer to an array of allocated memory
The sizeof operator can take the datatype of a structure as an argument, but cannot take an instance of that structure
The malloc() and free() functions are the only functions necessary for writing programs that use dynamic memory allocation
|
1, 2, 4
Which header file includes the declaration of the malloc() function?
%010stdio.h
%010stdlib.h
%010math.h
%010ctype.h

2

Which of the following pieces of code allocates memory to a pointer ptr1, which points to a structure of type NODE?

%010ptr1 = malloc(sizeof(NODE);
%010ptr1 =((NODE *)malloc(sizeof(NODE)));
%010ptr1 =((NODE)malloc(sizeof(NODE)));
%010ptr1 =((NODE *)malloc(NODE));

2
Of which node does each node in a linked list in ANSI C contain the memory address?

The next node
The first node
The last node

1

Which of the following lines of code links node c to node b in a list?
%010c->next=&b;
%010b->next=&c;
%010cnext=b;
&c=next&b;
1

Which of the following is used to define a pointer hdr to a structure of type NODE?

hdr*NODE;
*hdr NODE;
NODE *hdr;
NODE hdr;
3

Which of the following header files are needed to build and print a linked list?
%010stdio.h
%010stdlib.h
%010locale.h
%010string.h

1, 2

Comments

Popular Posts