Skip to main content

Posts

Hierarchy of Operations

The preference in which arithematic operations are performed in an arithematic expression is called as Hierarchy of operations. Its very important in C Programming to predefine the Hierarchy of operations to the C compiler in order to solve the given arithematic expression correctly. e.g.: If a programmer wishes to perform ,z=a+b/c;it may be interpretted as z=(a+b)/c or z=a+(b/c). and if a=3,b=6,c=2 then using the same expression we will obtain two different answwers as z=4.5 or z=6. To avoid this condition we must be aware of hierarchy of operations used in C programming. In arithematic expressions scanning is always done from left to right. The priority of operations is as shown below, Priority Operators First Paranthesis os brackets() Second Multiplication & Divison Third Addition & Substraction Fourth Assignment i.e.= If we consider the logical operators used in C language,the operator precedence will be like; Operators Type ! Logical ...

Increment-Decrement Operators

PRE/POST INCREMENT/DECREMENT OPERATORS(Unary operators) In programming we often require to increment value of certain variable in step of one or may require to decrement a value. This is usually written as i=i+1 for incrementing the value of variable i or i=i-1 to decrement the value of i. To accomplish this C language provides unary operators called as increment/decrement operators.Using these operators the above variable can be written as i++ or ++i. If ++ is after the variable then it is called as post increment and if it is before the variable then it is called as predecrement. In case of post increment(i++) the old value of the variable is used first and then the increment in the value of variable is done. In preincrement the value of variable is incremented first and then this value is used in the expression. same is in the case of decrement,i.e.pre decremant and post decrement, denoted as --i and i--.

Using symbolic Constants(#define)

Using Symbolic constants(#define) While developing a program in C language,we often use certain unique constants in a program.These const. may appear repeatedly in a C program,at number of places. Foe example,if we want to calculate the area of n number of circles,we require a constant 3.14 which is the value of'pi'. Now we may like to change the value of pi from 3.14 to 3.14159.To achieve this we will have to search through-out the program and explicitly change the value of pi whereever it has been used.If any value is left unchanged the program will produce wrong results.When we use variable ,value may change accidently,which results to wrong output. To avoid these type of mistakes w use symbolic constants in our C program. the syntax of a symbolic constant is; #define symbolic name value e.g. #define pi 3.14159 #define total 100

Inpu-output functions(Formatted)

Formatted Functions The formatted functions used in C programming are printf and scanf functions. Printf prints the formatted output on screen as specified in format specifier.This function can also be used for displaying all the datatype variables. e.g. printf(char,var1,var2,....); This function is used to enter the data. The scanf function accepts the formatted input from user as specified in format specifier & in variable address given as parameter. e.g. scanf("%d",&char); Example: main() { int x; char A; printf("\nx=%d",x); printf("\nx=%c",ch); printf("\nPress any key to continue"); getch(); } In the program above \n is the new line character.

Inpu-Output functions(Unformatted)

The C environment assumes that the standard input device(keyboard) and the standard output device(Monitor) are always connected to the C environment. Here's a list of some unformatted functions used in C along with their uses. Input / Output Functions Unformatted functions getch() Waits for user to press any key, returns the key pressed that can be assigned to variable getche() like getch() but echoes character pressed to screen getchar() Accepts one character from user, terminates only when user presses enter. Even if user typed more than one character return first one character only. putchar() can pass character type parameter, a single character that you want to appear on screen. gets() By passing character array as parameter can. accept string input including spaces. puts() By passing character array as parameter can display the content of string

C - The Programmer's Language

C - The Programmer's Language C language is widely famous and founds its applications everywhere because of its versatility and flexibility.In fact C language is a Programmers’s language. Not all computer programming languages are for programmers. For instance the COBOL and BASIC are not the languages for programmers.C was created,influenced, and tested by working programmers. That’s the reason C gives the programmer what the programmer wants.C is the language with few restrictions, few complaints, block structures, stand alone functions, and a compact set of keywords.Using C Language , you can nearly achieve the efficiency of assembly code combined with the structure of ALGOL.This has made C language highly popular between professional programmers. C was initially used for systems programming. Here are few example of system programming; 1) Operating systems 2) Interpreters 3) Editors 4) Compilers 5) File utilities 6) Performance enhancers 7) Real-time executives C founds wide...

Format Specifiers

Format Specifiers: The format specifiers are used in C programming to specify the format of the datatypes. The various format specifiers used in C programming are as follows; %d : Used for getting integer. %c : Used for getiing character output. %f : For float value. %l : For long integer. %s : For a string.