#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> #define INFINITELOOP while(1) int main() { INFINITELOOP printf("CuriousTab"); return 0; }
The macro INFINITELOOP while(1) replaces the text 'INFINITELOOP' by 'while(1)'
In the main function, while(1) satisfies the while condition and it prints "CuriousTab". Then it comes to while(1) and the loop runs infinitely.
#ifndef XSTRING_H
#define XSTRING_H defines the same preprocessor symbol,
Finally, the last line of the file, #endif
Example: #define CUBE(X)(X*X*X)
#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() { printf("India" "CURIOUSTAB\n"); return 0; }
#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; }
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.