Quiz 4

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which of the following is the reference operator? a. & b. / c. ++ d. *

a. &

What is the output of the following code? #include<stdio.h> void fun( int*, int* ); int main( int argc, char* argv[] ){ int i=5, j=2; fun( &i, &j ); printf( "%d, %d", i, j ); return 0; } void fun( int *i, int *j ){ *i = *i * *i; *j = *j * *j; } a. 25, 4 b. 4, 25 c. 5, 2 d. 10, 4

a. 25, 4

Which of the following statements correctly dynamically allocates an array for 10 integers? a. int *m = (int *) malloc( 10 * sizeof( int ) ); b. int *m = (int *) malloc( 10 ); c. int *m = (int *) malloc( 10 * int ); d. int *m = (int *) malloc( int ) * 10;

a. int *m = (int *) malloc( 10 * sizeof( int ) );

Which of the following printf statements print out the memory address that the pointer variable ptr is point at? a. printf( "%p", ptr ); b. printf( "%d", (void *) ptr ); c. printf( "%lf", ptr ); d. printf( "%d", *ptr );

a. printf( "%p", ptr );

What are the contents of the numbers array at the end of this code? int numbers[] = { 35, 57, 78, 66, 41, 12 }; int *ptrA = numbers; int *ptrB = ptrA + 2; *ptrB = 100; *ptrA = 100; a. 100, 100, 78, 66, 41, 12 b. 100, 57, 100, 66, 41, 12 c. 35, 57, 78, 66, 41, 12 d. 0, 0, 0, 0, 0, 0

b. 100, 57, 100, 66, 41, 12

Consider these statements: int value = 57; int *ptr = ?????; What is the correct expression to make the variable ptr point at the address of value? a. 57 b. value c. &value d. *value

c. &value

What is the output of the following code? int numbers[] = { 35, 57, 78, 66, 41, 12 }; int *ptrA = numbers; int *ptrB = ptrA + 2; int *ptrC = ptrB + 1; printf( "%d, %d, %d\n", *ptrA, *ptrB, *ptrC ); a. 66, 35, 41 b. 66, 78, 41 c. 35, 78, 66 d. 35, 78, 57

c. 35, 78, 66

From where is memory dynamically allocated? a. Harddrive b. Static c. heap d. stack

c. heap

What is the output of the following code? void f1 (int a, int b){ int c; c=a; a=b; b=c; } void f2 ( int *a, int *b){ int c; c=*a; *a=*b; *b=c; } int main(){ int a=4, b=5, c=6; f1(a, b); f2(&b, &c); printf ("%d", c-a-b); return 0; } a. -7 b. -3 c. 5 d. -5

d. -5

Which of the following is NOT the correct way of printing out the contents of the numbers array using pointers? a. int numbers[] = { 35, 57, 78, 66, 41, 12 }; int i = 0; int *ptr = numbers; for( i = 0; i < 6; i++ ) { printf( "%d\n", *( ptr + i ) ); } b. int numbers[] = { 35, 57, 78, 66, 41, 12 }; int i = 0; int *ptr = numbers; for( i = 0; i < 6; i++ ) { printf( "%d\n", *ptr ); ptr = ptr + 1; } c. int numbers[] = { 35, 57, 78, 66, 41, 12 }; int i = 0; int *ptr = numbers; for( i = 0; i < 6; i++ ) { printf( "%d\n", *ptr++ ); } d. int numbers[] = { 35, 57, 78, 66, 41, 12 }; int i = 0; int *ptr = numbers; for( i = 0; i < 6; i++ ) { printf( "%d\n", ++*ptr ); }

d. int numbers[] = { 35, 57, 78, 66, 41, 12 }; int i = 0; int *ptr = numbers; for( i = 0; i < 6; i++ ) { printf( "%d\n", ++*ptr ); }


संबंधित स्टडी सेट्स

GENETICS EXAM 1-4 (COMBINED) UH LIN/DAANE

View Set

Lesson 14: Andrew Jackson and the Growth of American Democracy

View Set

SWE - chapter 2 :Software processes

View Set

Chapter 54: Management of Patients With Kidney Disorders

View Set

Who, what, when, where, why, how

View Set

accounting chapter 11: pre test/objective test

View Set

26.3- Spermatogenesis occurs in the testes and produces mature sperm

View Set

Systems Analysis and Design | Chapter 1

View Set