Showing posts with label escape sequence. Show all posts
Showing posts with label escape sequence. Show all posts

Sunday, 30 November 2014

Format Specifiers and Escape Sequences


Format Strings and Escape Sequences:-

All format specifiers start with a percent sign (%) and are followed by a single letter indicating the type of data and how data are to be formatted.

List of commonly used format specifiers:


%c – used for single char in C
scanf(“%c”, &ch);
printf(“%c”, ch);


%d – decimal number (whole number)
scanf(“%d”, &num);
printf(“%d”, num);


%e – scientific notation/exponential form
scanf(“%e”, &result);
printf(“%e”, result);


%f – number with floating or decimal point
scanf(“%f”, &pesos);
printf(“%f”, pesos);


%u – unsigned number
scanf(“%u”, &nos);
printf(“%u”, nos);


%x – hexadecimal number
scanf(“%x”, &value);
printf(“%x”, value);


%X – capital number for hexadecimal number
scanf(“%X”, &nos);
printf(“%X”, nos);


%o – octal number
scanf(“%o”, &value);
printf(“%o”, value);


%s – string of characters
scanf(“%s”, str);
printf(“%s”, str);

%% - print a percent sign
scanf(“%%”, &value);
printf(“%%”, value);

List of commonly used escape sequences:

\\ - prints backslash

\’ - prints single quotes

\” - prints double quotes

\? - prints question mark

\n - newline

Associativity of Operators:


i = 2 * 3 / 4 + 4 / 4 + 8 - 2 + 5 / 8

i = 6 / 4 + 4 / 4 + 8 - 2 + 5 / 8 operation: *

i = 1 + 4 / 4 + 8 - 2 + 5 / 8 operation: /

i = 1 + 1+ 8 - 2 + 5 / 8 operation: /

i = 1 + 1 + 8 - 2 + 0 operation: /

i = 2 + 8 - 2 + 0 operation: +

i = 10 - 2 + 0 operation: +

i = 8 + 0 operation : -

i = 8 operation: +

_______________________________________________________________________



kk = 3 / 2 * 4 + 3 / 8 + 3

kk = 1 * 4 + 3 / 8 + 3 operation: /

kk = 4 + 3 / 8 + 3 operation: *

kk = 4 + 0 + 3 operation: /

kk = 4 + 3 operation: +

kk = 7 operation: +

________________________________________________________________________