#include<stdio.h> #include<stdarg.h> int main() { void display(int num, ...); display(4, 12.5, 13.5, 14.5, 44.3); return 0; } void display(int num, ...) { float c; int j; va_list ptr; va_start(ptr, num); for(j=1; j<=num; j++) { c = va_arg(ptr, float); printf("%f", c); } }
#include; int main() { printf("%x\n", -1>>1); return 0; }
Binary of 1(2byte) : 0000 0000 0000 0001 Representing -1: 1s complement of 1(2byte) : 1111 1111 1111 1110 Adding 1 to 1's comp. result : 1111 1111 1111 1111 Right shift 1bit(-1>>1): 1111 1111 1111 1111 (carry out 1) Hexadecimal : f f f f (Filled with 1s in the left side in the above step)Note:
1. Fill with 1s in the left side for right shift for negative numbers.
2. Fill with 0s in the right side for left shift for negative numbers.
3. Fill with 0s in the left side for right shift for positive numbers.
4. Fill with 0s in the right side for left shift for positive numbers.
#include<stdio.h> int main() { enum status { pass, fail, atkt}; enum status stud1, stud2, stud3; stud1 = pass; stud2 = atkt; stud3 = fail; printf("%d, %d, %d\n", stud1, stud2, stud3); return 0; }
stud1 = pass (value is 0)
stud2 = atkt (value is 2)
stud3 = fail (value is 1)
Hence it prints 0, 2, 1
#include<stdio.h> int main() { char ch; ch = 'A'; printf("The letter is"); printf("%c", ch >= 'A' && ch <= 'Z'? ch + 'a' - 'A':ch); printf("Now the letter is"); printf("%c\n", ch >= 'A' && ch <= 'Z'? ch : ch + 'a' - 'A'); return 0; }
Step 2: printf("The letter is"); It prints "The letter is".
Step 3: printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'a' - 'A':ch);
The ASCII value of 'A' is 65 and 'a' is 97.
Here
=> ('A' >= 'A' && 'A' <= 'Z') ? (A + 'a' - 'A'):('A')
=> (TRUE && TRUE) ? (65 + 97 - 65) : ('A')
=> (TRUE) ? (97): ('A')
In printf the format specifier is '%c'. Hence prints 97 as 'a'.
Step 4: printf("Now the letter is"); It prints "Now the letter is".
Step 5: printf("%c\n", ch >= 'A' && ch <= 'Z' ? ch : ch + 'a' - 'A');
Here => ('A' >= 'A' && 'A' <= 'Z') ? ('A') : (A + 'a' - 'A')
=> (TRUE && TRUE) ? ('A') :(65 + 97 - 65)
=> (TRUE) ? ('A') : (97)
It prints 'A'
Hence the output is
The letter is a
Now the letter is A
#include<stdio.h> int main() { int k, num=30; k = (num>5? (num <=10? 100 : 200): 500); printf("%d\n", num); return 0; }
Example:
#include<stdio.h>
int mul(int, int); /* Function prototype */
int main()
{
int a = 4, b = 3, c;
c = mul(a, b);
printf("c = %d\n", c);
return 0;
}
int mul(int a, int b)
{
return (a * b);
return (a - b); /* Warning: Unreachable code */
}
Output:
c = 12
#include<stdio.h> int main() { char *str; str = "%s"; printf(str, "K\n"); return 0; }
#include<stdio.h> int main() { char str1[] = "India"; char str2[] = "CURIOUSTAB"; char *s1 = str1, *s2=str2; while(*s1++ = *s2++) printf("%s", str1); printf("\n"); return 0; }
#include<stdio.h> int main() { int x=30, *y, *z; y=&x; /* Assume address of x is 500 and integer is 4 byte size */ z=y; *y++=*z++; x++; printf("x=%d, y=%d, z=%d\n", x, y, z); return 0; }
#include<stdio.h> int main() { char *p; p="hello"; printf("%s\n", *&*&p); return 0; }
#include<stdio.h> int main() { int i=3, *j, k; j = &i; printf("%d\n", i**j*i+*j); return 0; }
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.