#include<stdio.h> float a=3.14; double b=3.14;
To print a double value, %lf is used as format specifier.
Therefore, the answer is printf("%f %lf", a, b);
#include <stdio.h>
int main(void)
{
char string[80];
printf("Enter a string:");
gets(string);
printf("The string input was: %s\n", string);
return 0;
}
Output:
Enter a string: CuriousTab
The string input was: CuriousTab
#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() { struct emp { char *n; int age; }; struct emp e1 = {"Dravid", 23}; struct emp e2 = e1; strupr(e2.n); printf("%s\n", e1.n); return 0; }
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int num1 = 12345;
float num2 = 5.12;
char str1[20];
char str2[20];
itoa(num1, str1, 10); /* 10 radix value */
printf("integer = %d string = %s \n", num1, str1);
sprintf(str2, "%f", num2);
printf("float = %f string = %s", num2, str2);
return 0;
}
// Output:
// integer = 12345 string = 12345
// float = 5.120000 string = 5.120000
Examples of valid (but not very descriptive) C variable names:
=> foo
=> Bar
=> BAZ
=> foo_bar
=> _foo42
=> _
=> QuUx
#include<stdio.h> typedef unsigned long int uli; typedef uli u; int main() { uli a; u b = -1; a = -1; printf("%lu, %lu", a, b); return 0; }
For 'long int' system will occupy 4 bytes (32 bits).
Therefore,
Binary 1 : 00000000 00000000 00000000 00000001
To represent -1, system uses the 2's complement value of 1. Add 1 to the 1's complement result to obtain 2's complement of 1.
So, First take 1's complement of binary 1 (change all 0s to 1s and all 1s to 0s)
1's complement of Binary 1:
11111111 11111111 11111111 11111110
2's complement of Binary 1: (Add 1 with the above result)
11111111 11111111 11111111 11111111
In HexaDecimal
11111111 11111111 11111111 11111111 = FFFF FFFF FFFF FFFF
In Unsigned Integer
11111111 11111111 11111111 11111111 = 4294967295.
#include<stdio.h> int main() { int x = 30, y = 40; if(x == y) printf("x is equal to y\n"); else if(x > y) printf("x is greater than y\n"); else if(x < y) printf("x is less than y\n") return 0; }
printf("x is less than y\n") here ; should be added to the end of this statement.
#define P printf("%d\n", -1^~0); #define M(P) int main()\ {\ P\ return 0;\ } M(P)
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.