We discussed the distinction between two areas of memory: the heap and the run-time stack. Suppose that variable p has type int*. Which of the following is a correct C++ statement or statement sequence that makes p point to newly allocated memory in the heap?
Suppose that p is defined to point to memory as in the preceding question. Which of the following stores 25 in the integer variable to which p points.
What is the value of variable x after performing the following sequence of statements?
int x = 50; int* p = &x; *p = 4;
What is the value of variable x after performing the following sequence of statements?
int y = 7; int x = 35; int* p = &x; p = &y;
Which of the following will create an array of 30 integers called Orange in the run-time stack?
Which of the following will create an array of 30 integers called Orange in the heap?
Suppose that a C++ program contains the following statements.
int* p; p[0] = 1;Which of the following is a true statement about what happens?
Write a C++ definition of function mean(A, n), which returns the mean of the values in array A in indices from 0 to n-1. Array A contains values of type double. (The mean is the sum of the values divided by n.)
Write a C++ definition of function isBlank(s) that takes a null-terminated string s and returns true (1) if s contains only blanks and tabs, false (0) if s contains a character other than a blank or tab. isBlank("") should return true. (Note: The tab character is '\t'.)
Write a C++ definition of a function dup(s) that takes a null-terminated string s and yields a copy of s, also as a null-terminated string, in memory that is allocated in the heap.