Sei sulla pagina 1di 5

C Programming

Variable length 1-31 character(alphabets digits and underscores) *Some compiler


can assign variable name upto 247 characters
First character must be alphabet or underscore
There are 32 Keywords available in C
When main() always returns 0, that means that it has been succesfully executed
while a non zero returns means problem has occured.
There are about 45 Operators available in C but still no operator for exponentiation
printf() can also print value of expression
& means 'Address of' operator and it gives the location number used by variable in
the memory
when we want to take multiple input from the same scanf() then we can add
variables from console by adding space, tab or new line between all those variables
There are basically 3 types of instruction in C:
1) Type Declaration
2) Arithmetic Instruction
3) Control Instruction
We cannot use a variable before it has been defined (int a =10, b=a+6; //OK) but
(int b = a+6, a=10; //Not ok)
C allows us to write only one variable on left hand side of '=' Operator
The '%' Operator cannot be applied on Float Variable, and the sign of remainder is
always same as that of numerator
When the type of the Expression and the Type of the variable on the Left Hand Side
of the assignment Operator may not be same , under such conditions the value
of the expression is promoted or demoted depending on the type of the variable on
left hand side of '='

Priority/Heirarchy of Operator
1) !
2) / * %
3) + 4) < > <= >=
5) == !=
6) &&
7) ||
8) =

Control Instruction
1) Sequence Control Instruction
2) Selection or Decision Control Instruction
3) Repetition or Loop Control Instruction
4) Case Control Instruction

C has 3 decision making instructions


1) if statement
2) if-else statement
3) switch statement, conditional operators

In C a non zero is considered as true, whereas only 0 is considered as false

C has 3 Logical Operators


1) &&
2) ||
3) !

In the Else-IF Ladder, the last ELSE is Optional


a > b ? g =a : g =b ; // NOT OK ERROR
a > b ? g =a : (g = b); // OK
The Limitation of conditional Operator is that only one statement is allowed after '?'
or ':'
A-Z {65-90}
a-z {97-122}
0-9 {48-57}
special symbols {0-47,58-64,91-96,123-127}
C Programming supports 3 methods for Looping
1) for
2) while
3) do while

In C Programming , We should only find Factorial of a number less than 34 because


after that the result is out of range if it is declared as int variable

When using Switch Statement make sure u didn't write floating point number as
case arguments nor we can test it in switch() as mentioned below
These all statements regarding switch statement is correct
switch(i+j*k);
switch(23+45%4*k);

switch(a<4 && b >7);


case 3+7 : //ok
case a+b : //not ok
switch works faster than an equivalent if else ladder, this is because the compiler
generates a jump table for a switch during compilation, as a result
during execution it simply refers the jump table to decide which case should be
executed, rather than actually checking which case should be executed.
while condition in if else are evaluated at execution time thats why they are slower
There is no limit on number of functions that might be present in C
Any function can be called from any function, even main() can be called from
another function.
A function cannot be defined in another function.
There is no restriction on number of return statements that may be present in a
function. Also return statement need not to be present at the end of the called
function. A return statement can return only one value at a time.
The Formal Arguments and the local variables defined inside a function are created
at a place in memory called Stack. When the control returns from the function the
stack is cleaned up. Either the calling function or the called function clears the Stack
which is decided by calling function.
Standard calling conventions:
Arguments are passed from right to left.
Stack is cleaned up by called function.
The Address of the 0th Element often called base Address can also be passed to a
function by just passing the array name instead of &arrName[0]
All the following are same
Num[i]
*(Num + i)
*(i + Num)
i[Num]
While initializing a 2D Array, it is necessary to mention the second(column)
dimension whereas first dimension (row) is Optional.

Strings
We cannot assign a string to another whereas we can assign a char pointer to
another char pointer.
Char s1[] = hello;
Char s2[10];
Char *s = Good Morning;
Char *q;
S2 = s1 ; //Error
Q=s; //works
Once a String has been defined it cannot be initialized to another set of characters,
but such operation is perfectly valid for Pointers
Char s1[] = Hello;
Char *p = Hello;
S1 = Bye ; // Error
P = Bye;// Works
Bit Operations are only performed on int and char but not on Floats and doubles.

Potrebbero piacerti anche