What is the Output Chapter 05

What is the Output - 1 Find the error in each of the following segments a int*number cout < number < endl b float fval*realPtr =&fval long

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

View Full Document Right Arrow Icon
1. Find the error in each of the following segments: a) int *number; cout << number << endl; b) float fval, *realPtr = &fval; long lval, *integerPtr = &lval; integerPtr = realPtr; c) int *x, y = 10; x = y; d) char s[] = "this is an array"; for ( ; *s != '\0'; s++) cout << *s << ' '; e) short result, *numPtr = &result; void *genericPtr = numPtr; result = *genericPtr + 7; f) float x = 19.34; float xPtr = &x; cout << xPtr << endl; Answer : a) Pointer " number " does not point to a valid address. Assigning " number " to an address would correct the problem. b) A pointer of type float cannot be directly assigned to a pointer of type long. c) Variable y is not a pointer, and therefore cannot be assigned to x. Change the assignment statement to: x = &y; d) " s " is not a modifiable value (the name of the array is a constant address). Attempting to use operator ++ is a syntax error. e) A void * pointer cannot be dereferenced. f) " xPtr " is not a pointer and therefore cannot be assigned an address. Place a
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/27/2010 for the course DS csc 270 taught by Professor Dr.m.g during the Spring '10 term at Notre Dame University-Louaize.

Page1 / 7

What is the Output - 1 Find the error in each of the following segments a int*number cout < number < endl b float fval*realPtr =&fval long

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

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