Four Important aspects of any language:
Why is C used in some parts of Operating systems?
Speed of execution.
Device drivers are written in C.
Steps of learning C:
The C character Set
All alphabets, Capital and small.
All digits 0-9
Special Symbols o keyboard [31].
[ ~ is but ` is not valid]
Constant, Variable and Keywords:
These formed by the combination of the C character set.
Constants: Entity with a fixed value.
Variables; Entity with changing values.
Variable names theory:
The memory locations are given names and since the value stored in these memory keeps changing hence called variable names.
This allows us to retrieve and use the value stored in the memory location.
Types of C constant:
Rules Of Integer Constant:
Rules for constructing Real Constants:
aka Floating Point Constants. expressed in 2 forms: 1. Fractional Form: a. at least 1 digit. b. Decimal point Must. c. Can be +ve or -ve, default +ve d. No commas, blanks allowed.
Rules for Constructing Character Constants:
Character constant has max length of 1 character.
Enclosed in inverted commas, both single inverted, towards left.
like : ‘A’
‘1’
‘@’
In a language, the type of variables supported depends on ?
the type of constant supported.
Rules for constructing Variable Names:
These rules apply for all types of primary and secondary variables.
To differentiate between variables what is done?
Type declaration statements.
int varname;
float varname;
char varname;
C keywords:
keywords cant be used as var names.
they are already explained to the compiler.
AKA reserved words
There are 32.
auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while
Compiler Specific keywords:
ANSI said they should be preceded by 2 underscores.
like __near, __far, __asm
C program
how do instructions or statements make them?
Each instruction is written as a separate statement.
Therefore, a C program compromises of a series of statements.
They must appear in the order in which we expect them to execute.
To increase readability u can insert blacnk spaces btw words but not btw varnames, constant, keyword.
Statements are entered in small case letters.
Statement terminator:
;
Every statement ends with a ;
Comments:
Comment enclosed in /* */
can be anywhere, even btw the statement.
To explain code or provide information.
Compiler Completely Ignores it.
Can comments be multiline?
Yes
Can comments be nested?
NO
C is also called as free form cuz:
No specific rules for position at which a statement should be written.
Declare a variable:
and whats initialisation?
int n; int or float or char Declare before using. Assigning value to it is intialising. int i = 10; /* declared and initialised */
function printf()
printf( “”,);
format string may contains format specifiers : %f to print real value %d for int %c for char %s - char. %p - address. %u - unsigned Integer.
list of variables can contain Expressions.
NewLine
Takes cursor to next line.
\n
One of the Escape Sequences.