Bitbox page 197 ques 3 c programming er explain
(64>>(2+1-2)) & (~(1<<2)) becomes
(64>>1) & (~(1<<2)).
In binary,
(0100 0000>>1) & (~(0000 0001<<2)
(0010 0000) & (~(0000 0100))
0010 0000 & 1111 1011 ( ~ equal to NOT )
0010 0000 = 32 (in decimal)
#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)
Explanation: Array name in C is implemented by a constant pointer. It is not possible to
apply increment and decrement on constant types
Bitbox page 197 ques 4 c programming er explain
#include<stdio.h>
int main()
{
int arr[]={2, 3, 4, 1, 6};
printf("%u, %u, %u\n", arr, &arr[0], &arr);
return 0;
}
A. 1200, 1202, 1204
B. 1200, 1200, 1200
C. 1200, 1204, 1208
D. 1200, 1202, 1200
Answer & Explanation
Answer : Option B
Explanation :
Step 1: int arr[]={2, 3, 4, 1, 6}; The variable arr is declared as an integer array and initialized.
Step 2: printf("%u, %u, %un", arr, &arr[0], &arr); Here,
The base address of the array is 1200.
=> arr, &arr is pointing to the base address of the array arr.
=> &arr[0] is pointing to the address of the first element array arr. (ie. base address)
Hence the output of the program is 1200, 1200, 1200
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
and it is initialized with the values.
Step 2: printf("%dn", sizeof(arr)/sizeof(arr[0]));
The variable arr has 4 elements. The size of the float variable is 4 bytes.
Hence 4 elements x 4 bytes = 16 bytes
sizeof(arr[0]) is 4 bytes
Hence 16/4 is 4 bytes
Hence the output of the program is '4'.