Skip to main content

Posts

Showing posts from May 11, 2008

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