0% found this document useful (0 votes)
30 views

Quiz 3 Solution

Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
30 views

Quiz 3 Solution

Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
Name: Branch: SNU ID: Ques.1 Choose the correct answer: ‘What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array? (a) The element will be set to 0. (b) The compiler would report an error. The program may crash if some important data gets overwritten. (d) The array size would appropriately grow. 2, ‘How many values a function can return at a time? ‘only one (©) depends on the system (b) infinite values @2 3. A static variable is one (a) which can’t be initialized (b) which is same as automatic variable but it is placed at the head of the program (©) which is initialized once and can’t be changed at run time (hich retains its value throughout the life of the program 4, Incase both external and auto variables are declared with the same name in a program, the priority is given to which of the variables (a) complier dependent Gio variable (b) depends on logic ((d) external variable 5. Arrays are passed as arguments to a function by «sateen (©) both value and reference (b) context (@) value Ques.2 Find the Output of the following codes: 1. #include void main() ‘ 4 int num =5, int *ptr= # Co printi(“sedinYd", num, (*pte)); } 2. #include void main) 3. includes ‘ void main() inti, arr[10]; t for(i=0; i<10; i++) int arr[] = {0, 1, 2, 0, 1, 2, 0, 1, 2}; 1k printf(“%d”, arr[3]); ; i105 +4) printf%d”, arrfar{3]D; © #241] = -15 printf(“%ed”, arr[arr[3}+are{1])); | §=0; i<10; i++) printf(“%d”, arefarrfarrfarr[1]]1D; | printf(“%d"arr[i]); } 3 4. Hinclude void main) 7, Hinclude { void main() int arr{] = (0, 1, 2,0, 1,2, 0, 1,2} int i, arr2[10); for(i=0; i<10; i+) arr2fi] = arrl [9-1 for(i=0; i<10; i++) printf(“%d",arr2[i]); 5, 1, 15, 20, 25}; B , 3,a,16 OkAlo0€l OR! O a 5. #include 8. Hinclude void main = # “%edin", *&mum), S ”*&*&num); 10 printf(“%din”, *&ptr): Add Os n printf(“%d\n”, **&ptr); aaaed printf(“%din”, &** &ptr); printf("%din", p); } Addie of } hum 6. #include 9. Hinclude void main() void main) int arf ]= (1, 2,3, 4, 5}, is int p=10; i void main() 4 { float arr{] = (12.4, 2.3, 4.5, 6.7}; printf("%d\n", 11. #include void main() int arr[5], i=0; while(i<5) for(i 0; i<5; printi("%d,", afi); ) Gorboge, 1, 2, a, 12, #include void main() int af1] = {10}; printi("%d",0[a); 10 @ int mark 23) £(10, 20, 303, (49, (b) int marks{2][3] = {10, 20, 30, 40}; No -oflarr)/sizeoflarr{0)); 4 1, 50, 60}}; Euer 13. Hinclude void main) { Z,a int af5] = {5, 1, 15, 20, 25}; i,j, ms all]; jealli+s m=alit+]; printt("%d, Yd, %d", i, j, ms 3 14, #include void main { void funGint, int [); int arrf] = (1, 2,3, 4}; inti; fun(4, arr); forti=0; <4; i+) printf(“%d,”, ari); 3 void fun(int n, int arr{J) { int *p=0; inti=0; while(i++ What is the value of *(x+2)? 3 Ques.6 Choose the correct answer: 1. What is the right way to tialize array? Fito) = (2,4, 12, 5, 45, 5}s (b) intn{ } = (2, 4, 12, 5, 45, 5}; (©) int n{6} = (2,4, 12}; (a) int (6) = (2, 4, 12, 5, 45, 5}; Let x be an array. Which of the following operations are illegal? (a) Hx (b) x+1 © x44 aoe 3. What is the maximum number of dimensions an array in C may have? @2 (b) 8 © 20 @s Sr Theory no limit. The only practical limits are memory size and compilers. 4. What will be the output of the program? #include void main( (a0 0 { aumety (b) Garbage Value 0 int a[10}; (0 Garbage Value printf("%din%d", af-1], af12)); Lay Garbage Value Garbage Value } (@) Code will not compile

You might also like