#include<stdio.h> int main() { printf("India" "CURIOUSTAB\n"); return 0; }
#include<stdio.h> #define X (4+Y) #define Y (X+3) int main() { printf("%d\n", 4*X+2); return 0; }
#include<stdio.h> int main() { #ifdef NOTE int a; a=10; #else int a; a=20; #endif printf("%d\n", a); return 0; }
The macro #ifdef NOTE evaluates the given expression to 1. If satisfied it executes the #ifdef block statements. Here #ifdef condition fails because the Macro NOTE is nowhere declared.
Hence the #else block gets executed, the variable a is declared and assigned a value of 20.
printf("%d\n", a); It prints the value of variable a 20.
#include<stdio.h> int main() { static int arr[] = {0, 1, 2, 3, 4}; int *p[] = {arr, arr+1, arr+2, arr+3, arr+4}; int **ptr=p; ptr++; printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr); *ptr++; printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr); *++ptr; printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr); ++*ptr; printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr); return 0; }
#include<stdio.h> int main() { int arr[] = {12, 14, 15, 23, 45}; printf("%u, %u\n", arr, &arr); return 0; }
Step 2: printf("%u, %u\n", arr, &arr); Here,
The base address of the array is 65486.
=> arr, &arr is pointing to the base address of the array arr.
Hence the output of the program is 65486, 65486
#include<stdio.h> int main() { static int a[2][2] = {1, 2, 3, 4}; int i, j; static int *p[] = {(int*)a, (int*)a+1, (int*)a+2}; for(i=0; i<2; i++) { for(j=0; j<2; j++) { printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i), *(*(i+p)+j), *(*(p+j)+i)); } } return 0; }
#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; }
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("%d\n", 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'.
#include<stdio.h> int main() { void fun(int, int[]); int arr[] = {1, 2, 3, 4}; int i; fun(4, arr); for(i=0; i<4; i++) printf("%d,", arr[i]); return 0; } void fun(int n, int arr[]) { int *p=0; int i=0; while(i++ < n) p = &arr[i]; *p=0; }
Step 2: int arr[] = {1, 2, 3, 4}; The variable a is declared as an integer array and it is initialized to
a[0] = 1, a[1] = 2, a[2] = 3, a[3] = 4
Step 3: int i; The variable i is declared as an integer type.
Step 4: fun(4, arr); This function does not affect the output of the program. Let's skip this function.
Step 5: for(i=0; i<4; i++) { printf("%d,", arr[i]); } The for loop runs untill the variable i is less than '4' and it prints the each value of array a.
Hence the output of the program is 1,2,3,4
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.