Академический Документы
Профессиональный Документы
Культура Документы
C++ is C with added functionality and that around 90% of any C++ program is
actually C
The Structure of C Program
HEADER SECTION
*Optional
Contains name, short description, author of the program and date created
INCLUDE SECTION
FUNCTIONS SECTION
*Optional
User defined functions
MAIN PROGRAM SECTION
main()
{}
Header File
It contains definitions of functions and variables which can be incorporated into anyC
program by using the pre-processor #include statement.Standard header filesare
provided with each compiler, and cover a range of areas, string
handling,mathematical, data conversion, printing and reading of variables.
File Name
Related Functions
conio.h
Direct console I/O functions
ctype.h
Character-related functions
graphics.h
Graphics-related functions
math.h
Mathematical functions
stdio.h
Standard I/O functions
stdlib.h
Miscellaneous functions
string.h
String-related functions
A Simple C program
#include <stdio.h>
/* defines the routines for standard input
and output, such as printf, scanf, etc */
main()
/* informs the computer as to where the program starts */
{
/* signifies the begin segment of the program */
printf("Hello World!");/* this statement prints the word Hello World on the screen */
}
/* signify the end segment of the program */
Basic Output Statements
Command
Function
printf()
Used to print the output to the screen and
can be used with variables
puts()
Used to print a whole sentence on the
screen but cannot be used with variables
putchar()
Prints a single character on the screen
1 to 32 characters
Composed of one-word
Variables (identifiers) need to be declared before you can use them in a program.
#include <stdio.h>
int x,y;
/* global variables declaration */
char let='A';
main()
{
float area, pi=3.1416, radius;
/* local variables declaration */
char stud_name[20];
}Basic Input Commands
Command
Function
scanf()
Used to scan the keyboard for information
Usually placed after printf() statements
Used with integer, float and double data
gets()
Reads a string of character entered at the
keyboard
Used with string data
getche()
Reads a character from the keyboard
The key pressed is echoed to the screen
automatically
getch()
Operates like getche() except that the
character typed is not echoed to the screen
Format:
scanf(var_for, &var_name);
where:
var_for - %d for int, %c for char, %f for float, %e for double
var_name name of the variable (identifier)
gets(string_var_name);
where:
string_var_name a variable used in the program which is of string type
var_name=getche();
where:
HISTORY of Turbo C
1. In Pascal, you can use lower case and uppercase but in C, you are only allowed to use
lower case only for input and output.1. In
2. In Pascal comments are enclosed by { } or (* *); In C comment are enclosed in /* */
3. In Pascal, we use BEGIN and END in C {left curly braces signifies the beginning of
the program while right curly braces signifies the end of the program.
4. In Pascal, (;) semicolon is used as statement separator. While in C, it is a statement
terminator.
5. In Pascal, we use write or writeln to print the output list. In C, printf as write and
printf("backslash n") for writeln.
6. In Pascal, we use read or readln to read from the keyboard. In C scanf, gets, getch,
getche, getchar in different kind usage.
http://hubpages.com/hub/A-Brief-History-of-the-C-Language
Why Use C?
In today's world of computer programming, there are many high-level languages to
choose from, such as Pascal, BASIC, and Java. But C stands apart from all these
languages. This is due to its many desirable qualities. It is a robust language whose
rich set of built-in functions and operators can be used to write any complex logic
program. The C language compiler combines the capabilities of a low level language
with the features of a high level language. Therefore the language is suitable for
writing both system software as well as business packages & other software. You will
many compilers available in the market written in C.
Program written in c are very efficient and fast. This is due to its variety of data
types and powerful operators. It is many time faster than BASIC. This helps
developers in saving their valuable time.
C is a powerful and flexible language which helps system developers to deliver
various complex tasks with ease. C is used for diverse projects as operating
systems, word processors, graphics, spreadsheets, and even compilers for other
languages.
C is popular among professional programmers for programming, as a result, a wide
variety of C compilers and helpful accessories are available.
C is highly portable language. This means that a C program written for one
computer system (an IBM PC, for example) can be run on another system (a DEC
VAX system, perhaps) with little or no modification. Portability is enhanced by the
ANSI standard for C, the set of rules for C compilers.
Cs another striking feature is its ability to extend itself. A C program is basically a
collection of various function supported by C library (also known as header files). We
can also add our own functions to the C library. These functions can be reused in
other applications or programs by passing pieces of information to the functions, you
can create useful, reusable code.
Writing C program with user-defined functions makes program more simple and
easy to understand. Breaking a problem in terms of functions makes program
debugging, maintenance and testing easier.
As these features shows that C is an excellent choice for your first programming
language. But what is C++? You might have heard this term C++ and the
programming technique called Object-Oriented Programming (OOP). Possibly you're
wondering what the differences are between C and C++ and whether you should
learn C or C++.
C++ is a superset of C, means that C++ is the new improved version of C for the
latest programming needs. It contains everything C does, plus new additions for
OOP concept. If you will learn C++ later, you will find that almost everything which
you learnt in C is applicable in C++ too. In learning C, you are not only learning one
of today's most powerful and popular programming languages, but you are also
preparing yourself for other similar programming languages.
Another language that has gotten lots of attention is Java for its OOP and portability.
Java, just like C++, is based on C. If later you decide to learn Java, you will find that
almost everything you learned about C applies here.