1_Questions_9 - Pointers 5. The following program compiles,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CIS 15BG Questions Chapter 9: Pointers 1. Given the following definitions, what is the type of the corresponding expressions? Definition Expression Type? int **p; **p float ****q; ***q char ****r; 2. What is wrong with the following program fragment? int *p; int num; scanf( "%d", p ); 3. Given the following declarations: int x; char y; int *ptr1; char *ptr2; which of the following statements are not allowed? Why? a. x = y; b. ptr1 = ptr2; c. ptr1 = &x; d. x = &ptr1; e. ptr2 = &x; 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CIS 15BG Questions Chapter 9: Pointers 4. In the following program fragment show the configuration of the variables and the output. int a = 15 ; int b = 5; int *p; int *q; int **r; int **s; p = &a; q = &b; r = &p; s = &q; *p = *p + 5; (*q)--; (**r)++; *s = p; printf( "%__ %__ %__ %__ ", *p, *q, **r, *s ); Write the correct format descriptors ( %d or %p ) in the previous printf statement Output:____________________________ 2 a b r q p s
Background image of page 2
CIS 15BG Questions Chapter 9:
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Pointers 5. The following program compiles, but it gives a warning. If you ignore it and run the program, it gives you incorrect results. A. Explain what is wrong with this program B. Fix it, without changing the header of fun #include <stdio.h> double *fun ( double *px, double *py, double *pz ); int main ( void ) { double a = 12.5; double b = 30.3; double c = 25.7; double *ptr; ptr = fun( &a, &b, &c); printf( "%p %.2f\n", &a, a ); printf( "%p %.2f\n", &b, b ); printf( "%p %.2f\n", &c, c ); printf( "\n Largest:\n%p %.2f\n", ptr, *ptr ); return 0; } /* ===================================================== */ double *fun ( double *px, double *py, double *pz ) { double large = *px; if ( *py > large ) large = *py; if ( *pz > large ) large = *pz; return &large; } /* OUTPUT 0012FF78 12.50 0012FF70 30.30 0012FF68 25.70 Largest: 0012FEFC 0.00 */ 3...
View Full Document

This note was uploaded on 09/02/2011 for the course CIS 15BG taught by Professor Staff during the Winter '10 term at DeAnza College.

Page1 / 3

1_Questions_9 - Pointers 5. The following program compiles,...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online