The Character Set
Constant, Variable and Keyword
Constant
- Primary Constant(Integer, Real, Character)
- Secondary Constant(Array, Pointer, Structure, Union, Enum, Etc)
Rules for Constructing Integer Constant
- An Integer constant must have at least one digit.
- It must not have decimal point
- It can be either Positive or Negative.
- If no sign precedes an integer constant, it is assumed to be positive.
- No commas or blanks are allowed within an integer constant.
- The allowable range for integer constants is -2147483648 to +2147483647.
Rules for Constructing Real Constant
- A real Constant must have at least one digit.
- It must have a decimal point.
- It could be either positive or negative.
- Default sign is positive.
- No commas or blanks are allowed within real constant.
Rules for Constructing Character Constant
- A character constant is a single alphabet, a single digit or single symbol enclosed within single inverted commas.
- Both the inverted commas should point to the left. For example 'A','I','5','=' are valid character constant.
Rules for Constructing Variable Name
- A variable name is any combination of 1 to 31 alphabet, digit or underscores. Some compiler allow variable names whose length could be up to 247 characters. Still, it would be safer to stick to the rule of 31 characters. Do not create unnecessarily long variable name as it adds to your typing efforts.
- The first character in the variable name must be an alphabet or underscore.
- No commas or blanks are allowed within a variable name.
- No special symbol other than an underscore (as in gross_sal) can be used in a variable name.
- Eg: int name, symbol, address ;
float number, c_number, computer_code;
Data Type
1) Basic Data Types
a) Integer Type
int: A basic
integer type. Size typically 4 bytes. |
short: A
short integer type. Size typically 2 bytes. |
long: A long
integer type. Size typically 4 or 8 bytes. |
long long: A
longer integer type. Size typically 8 bytes. |
b) Floating- Point Type
float: Single
precision floating point. Size typically 4 bytes. |
double:
Double precision floating point. Size typically 8 bytes. |
long double:
Extended precision floating point. Size typically 8, 12, or 16 bytes,
depending on the system. |
c) Character Type
char: A
character type. Size typically 1 byte. Can hold a single character or small
integer. |
unsigned
char: An unsigned character type. Size typically 1 byte. |
signed char:
A signed character type. Size typically 1 byte. |
Derived Data Type
a) Array
b) Pointer
Variables that store memory addresses.
Example: int *ptr;
c) Struct
Collections of variables of different types grouped
together.
d) Union
Similar to structures but with all members sharing the same
memory location.
d) Enumeration
e) Void
Indicates that no value is available.
Commonly used in function return types to indicate that the
function does not return a value, and in pointers to specify a generic pointer
type.
Example:
Escape Sequence
Common Escape Sequences
- New Line "\n"
Example: printf("Hello\nWorld"); prints: - Horizontal Tab "\n"
Example: printf("Hello\tWorld"); prints: - Backspace "\b"
Example: printf("Hello\bWorld"); prints: - Carriage return "\r"
Example: printf("Hello\rWorld"); prints: - Form feed "\f"
Example:printf("Hello\fWorld");
might behave differently based on the system, often advancing to a new page. - Alert(Bell) "\a"
Example:printf("\a");
may produce a beep sound on some systems. - Backslash "\\"
Example: printf("C:\\Program Files"); prints: - Single Quote " \' "
Example: printf("It\'s OK."); prints: - Double Quote" \" "
Example: printf("She said, \"Hello.\""); prints: - Question Mark " \? "
Example: printf("What\?"); prints:
Numeric Escape Sequences
- Octal Number :"\ooo"
Example: printf("\101"); - Hexadecimal Number:"\xhh"
Example: printf(\x41);
Unicode Escape Sequences(C11 and later)
- \u is followed by 4 hexadecimal digits.
- \U is followed by 8 hexadecimal digits.
- Example: printf("\u03A9"); prints the Greek letter Omega (Ω).
- Example: printf("\U0001F600"); prints the Emoji (😀).
C keywords
auto |
double |
int |
Struct |
break |
else |
long |
switch |
case |
enum |
register |
typedef |
char |
extern |
return |
union |
continue |
for |
signed |
void |
default |
goto |
sizeof |
volatile |
do |
if |
static |
while |
0 Comments had been done yet:
Post a Comment