Access Specifiers
- %d : signed int
- %u : unsigned int
- %s : string
- %c : char
- %f : float
- %lf : double
- %o : octal
- %x or %p : hexadecimal
- %e or %E : scientific notation
- %hd : short int
- %ld : long int
Range of data types
The memory size of the basic data types may change according to 32 or 64-bit operating system.
Let's see the basic data types. Its size is given according to 32-bit architecture.
Data Types | Memory Size | Range |
---|---|---|
char | 1 byte | −128 to 127 |
signed char | 1 byte | −128 to 127 |
unsigned char | 1 byte | 0 to 255 |
short | 2 byte | −32,768 to 32,767 |
signed short | 2 byte | −32,768 to 32,767 |
unsigned short | 2 byte | 0 to 65,535 |
int | 2 byte | −32,768 to 32,767 |
signed int | 2 byte | −32,768 to 32,767 |
unsigned int | 2 byte | 0 to 65,535 |
short int | 2 byte | −32,768 to 32,767 |
signed short int | 2 byte | −32,768 to 32,767 |
unsigned short int | 2 byte | 0 to 65,535 |
long int | 4 byte | -2,147,483,648 to 2,147,483,647 |
signed long int | 4 byte | -2,147,483,648 to 2,147,483,647 |
unsigned long int | 4 byte | 0 to 4,294,967,295 |
float | 4 byte | |
double | 8 byte | |
long double | 10 byte |
The memory size of int for 64-bit architecture is 4 bytes and that of long int is 8 bytes.
- What is the output of the following C code?
- What is the output of the following C code?
- What is the output of the following C code for the following inputs
- 12 12
- 123 123
- 1234 1234
- What is the output of the following C code for the following inputs
- 12 12
- 123 123
- 1234 1234
- What is the output of the following C code for the following inputs
- 1.2 1.2
- 1.23 1.23
- 12.34 12.34
- What is the output of the following C code for the following inputs
- 1.2 1.2
- 1.23 1.23
- 12.34 12.34
- What is the output of the following C code for the following inputs
- abc
- abcde
- abcdefg
- What is the output of the following C code for the following inputs
- a
- abc
- abcd
- What is the output of the following C code for the following inputs
- a
- abc
- abcd
- What is the output of the following C code for the following inputs
- a
- abc
- abcd
- What is the output of the following C code for the following inputs
- a
- abc
- abcd
#include <stdio.h>
int main()
{
double num = 12345.6789;
printf("%e", num);
}
#include <stdio.h>
int main()
{
double num = 0.000123456789;
printf("%e", num);
}
#include <stdio.h>
int main()
{
int a, b;
scanf("%2d %3d", &a, &b);
printf("%d %d", a, b);
}
#include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
printf("a=%4d b=%3d", a, b);
}
#include <stdio.h>
int main()
{
float a, b;
scanf("%3f %4f", &a, &b);
printf("%f %f", a, b);
}
#include <stdio.h>
int main()
{
float a, b;
scanf("%f %f", &a, &b);
printf("a=%4.1f b=%7.2f", a, b);
}
#include <stdio.h>
int main()
{
char str[5];
scanf("%s", str);
printf("str=%s", str);
}
#include <stdio.h>
int main()
{
char str[10];
scanf("%3s", str);
printf("%s", str);
}
#include <stdio.h>
int main()
{
char str[5];
scanf("%s", str);
printf("str=%3s", str);
}
#include <stdio.h>
int main()
{
char str[10];
scanf("%s", str);
printf("%.3s", str);
}
#include <stdio.h>
int main()
{
char str[10];
scanf("%s", str);
printf("str=%8.3s", str);
}
Supression Character (%*d)
- If used with scanf(), then ignores the current value and takes the next value as input.
- If used with printf(), then prints some whitespaces and gives value of next variable till the last variable.
- What is the output of the following C code with input: 20 25 30 35?
- What is the output of the following C code with input: 20 25 30 35?
#include <stdio.h>
int main()
{
int a, b, c, d;
scanf("%*d %d %d %d", &a, &b, &c, &d);
printf("%d %d %d %d", a, b, c, d);
}
#include <stdio.h>
int main()
{
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
printf("%d %*d %d %d", a, b, c, d);
}
Comments
Post a Comment