Professional Documents
Culture Documents
Bitbox Page 197 Ques 3 C Programming Er Explain: (A) 2002 (B) 2004 (C) 2020 (D) Lvalue Required
Bitbox Page 197 Ques 3 C Programming Er Explain: (A) 2002 (B) 2004 (C) 2020 (D) Lvalue Required
#include <stdio.h>
int main()
{
int arr[5];
// Assume that base address of arr is 2000 and size of integer
// is 32 bit
arr++;
printf("%u", arr);
return 0;
}
(A) 2002
(B) 2004
(C) 2020
(D) lvalue required
Answer: (D)
#include<stdio.h>
int main()
{
int arr[]={2, 3, 4, 1, 6};
printf("%u, %u, %u\n", arr, &arr[0], &arr);
return 0;
}
Explanation :
Step 1: int arr[]={2, 3, 4, 1, 6}; The variable arr is declared as an integer array and initialized.
=> &arr[0] is pointing to the address of the first element array arr. (ie. base address)
Q.
What will be the output of the program ?
#include<stdio.h>
int main()
{
float arr[] = {12.4, 2.3, 4.5, 6.7};
printf("%d\n", sizeof(arr)/sizeof(arr[0]));
return 0;
}
A. 5
B. 4
C. 6
D. 7
Answer & Explanation
Answer : Option B
Explanation :
The sizeof function return the given variable. Example: float a=10; sizeof(a) is 4 bytes
Step 1: float arr[] = {12.4, 2.3, 4.5, 6.7}; The variable arr is declared as an floating point array
sizeof(arr[0]) is 4 bytes
Hence 16/4 is 4 bytes