C Programming

6
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

description

Details about C

Transcript of C Programming

C Programming

Variable length 1-31 character(alphabets digits and underscores) *Some compiler can assign variable name upto 247 charactersFirst character must be alphabet or underscoreThere are 32 Keywords available in CWhen 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 exponentiationprintf() can also print value of expression& means 'Address of' operator and it gives the location number used by variable in the memorywhen 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 variablesThere are basically 3 types of instruction in C:1) Type Declaration 2) Arithmetic Instruction3) Control InstructionWe 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 '=' OperatorThe '%' Operator cannot be applied on Float Variable, and the sign of remainder is always same as that of numeratorWhen 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 valueof 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 Instruction1) Sequence Control Instruction2) Selection or Decision Control Instruction3) Repetition or Loop Control Instruction4) Case Control Instruction

C has 3 decision making instructions1) if statement2) if-else statement3) switch statement, conditional operators

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

C has 3 Logical Operators1) &&2) ||3) !

In the Else-IF Ladder, the last ELSE is Optionala > b ? g =a : g =b ; // NOT OK ERRORa > b ? g =a : (g = b); // OKThe 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 Looping1) for2) while3) 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 belowThese all statements regarding switch statement is correctswitch(i+j*k);switch(23+45%4*k);switch(a7);case 3+7 : //okcase a+b : //not okswitch works faster than an equivalent if else ladder, this is because the compiler generates a jump table for a switch during compilation, as a resultduring 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 slowerThere is no limit on number of functions that might be present in CAny 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 sameNum[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 ; //ErrorQ=s; //works

Once a String has been defined it cannot be initialized to another set of characters, but such operation is perfectly valid for PointersChar s1[] = Hello;Char *p = Hello;S1 = Bye ; // ErrorP = Bye;// Works

Bit Operations are only performed on int and char but not on Floats and doubles.