Can you recommend any website which offers lessons for learning C language free?
I am an ABSOLUTE beginner.
Thanks a lot in advance.
btw, I'm 15.
Want to learn C computer language online?
This section contains a brief introduction to the C language. It is intended as a tutorial on the language, and aims at getting a reader new to C started as quickly as possible. It is certainly not intended as a substitute for any of the numerous textbooks on C.
The best way to learn a new ``human'' language is to speak it right from the outset, listening and repeating, leaving the intricacies of the grammar for later. The same applies to computer languages--to learn C, we must start writing C programs as quickly as possible.
An excellent textbook on C by two well-known and widely respected authors is:
The C Programming Language -- ANSI C
Brian W. C. Kernighan %26amp; Dennis M. Ritchie
Prentice Hall, 1988
Dennis Ritchie designed and implemented the first C compiler on a PDP-11 (a prehistoric machine by today's standards, yet one which had enormous influence on modern scientific computation). The C language was based on two (now defunct) languages: BCPL, written by Martin Richards, and B, written by Ken Thompson in 1970 for the first UNIX system on a PDP-7. The original ``official'' C language was the ``K %26amp; R'' C, the nickname coming from the names of the two authors of the original ``The C Programming Language''. In 1988, the American National Standards Institute (ANSI) adopted a ``new and improved'' version of C, known today as ``ANSI C''. This is the version described in the current edition of ``The C Programming Language -- ANSI C''. The ANSI version contains many revisions to the syntax and the internal workings of the language, the major ones being improved calling syntax for procedures and standarization of most (but, unfortunately, not quite all!) system libraries.
1. A First Program
Let's be polite and start by saluting the world! Type the following program into your favorite editor:
--------------------------------------...
#include %26lt; stdio.h%26gt;
void main()
{
printf("\nHello World\n");
}
--------------------------------------...
Save the code in the file hello.c, then compile it by typing:
gcc hello.c
This creates an executable file a.out, which is then executed simply by typing its name. The result is that the characters `` Hello World'' are printed out, preceded by an empty line.
A C program contains functions and variables. The functions specify the tasks to be performed by the program. The ``main'' function establishes the overall logic of the code. It is normally kept short and calls different functions to perform the necessary sub-tasks. All C codes must have a ``main'' function.
Our hello.c code calls printf, an output function from the I/O (input/output) library (defined in the file stdio.h). The original C language did not have any built-in I/O statements whatsoever. Nor did it have much arithmetic functionality. The original language was really not intended for ''scientific'' or ''technical'' computation.. These functions are now performed by standard libraries, which are now part of ANSI C. The K %26amp; R textbook lists the content of these and other standard libraries in an appendix.
The printf line prints the message ``Hello World'' on ``stdout'' (the output stream corresponding to the X-terminal window in which you run the code); ``\n'' prints a ``new line'' character, which brings the cursor onto the next line. By construction, printf never inserts this character on its own: the following program would produce the same result:
--------------------------------------...
#include %26lt; stdio.h%26gt;
void main()
{
printf("\n");
printf("Hello World");
printf("\n");
}
--------------------------------------...
Try leaving out the ``\n'' lines and see what happens.
The first statement ``#include %26lt; stdio.h%26gt;'' includes a specification of the C I/O library. All variables in C must be explicitly defined before use: the ``.h'' files are by convention ``header files'' which contain definitions of variables and functions necessary for the functioning of a program, whether it be in a user-written section of code, or as part of the standard C libaries. The directive ``#include'' tells the C compiler to insert the contents of the specified file at that point in the code. The ``%26lt; ...%26gt;'' notation instructs the compiler to look for the file in certain ``standard'' system directories.
The void preceeding ``main'' indicates that main is of ``void'' type--that is, it has no type associated with it, meaning that it cannot return a result on execution.
The ``;'' denotes the end of a statement. Blocks of statements are put in braces {...}, as in the definition of functions. All C statements are defined in free format, i.e., with no specified layout or column assignment. Whitespace (tabs or spaces) is never significant, except inside quotes as part of a character string. The following program would produce exactly the same result as our earlier example:
#include %26lt; stdio.h%26gt;
void main(){printf("\nHello World\n");}
The reasons for arranging your programs in lines and indenting to show structure should be obvious!
--------------------------------------...
2. Let's Compute
The following program, sine.c, computes a table of the sine function for angles between 0 and 360 degrees.
--------------------------------------...
/************************/
/* Table of */
/* Sine Function*/
/************************/
/* Michel Vallieres */
/* Written: Winter 1995*/
#include %26lt; stdio.h%26gt;
#include %26lt; math.h%26gt;
void main()
{
int angle_degree;
double angle_radian, pi, value;
/* Print a header */
printf ("\nCompute a table of the sine function\n\n");
/* obtain pi once for all */
/* or just use pi = M_PI, where
M_PI is defined in math.h */
pi = 4.0*atan(1.0);
printf ( " Value of PI = %f \n\n", pi );
printf ( " angle Sine \n" );
angle_degree=0;/* initial angle value */
/* scan over angle */
while ( angle_degree %26lt;= 360 )/* loop until angle_degree %26gt; 360 */
{
angle_radian = pi * angle_degree/180.0 ;
value = sin(angle_radian);
printf ( " %3d %f \n ", angle_degree, value );
angle_degree = angle_degree + 10; /* increment the loop index */
}
}
--------------------------------------...
The code starts with a series of comments indicating its the purpose, as well as its author. It is considered good programming style to identify and document your work (although, sadly, most people only do this as an afterthought). Comments can be written anywhere in the code: any characters between /* and */ are ignored by the compiler and can be used to make the code easier to understand. The use of variable names that are meaningful within the context of the problem is also a good idea.
The #include statements now also include the header file for the standard mathematics library math.h. This statement is needed to define the calls to the trigonometric functions atan and sin. Note also that the compilation must include the mathematics library explicitly by typing
gcc sine.c -lm
Variable names are arbitrary (with some compiler-defined maximum length, typically 32 characters). C uses the following standard variable types:
int -%26gt; integer variable
short -%26gt; short integer
long -%26gt; long integer
float -%26gt; single precision real (floating point) variable
double -%26gt; double precision real (floating point) variable
char -%26gt; character variable (single byte)
The compilers checks for consistency in the types of all variables used in any code. This feature is intended to prevent mistakes, in particular in mistyping variable names. Calculations done in the math library routines are usually done in double precision arithmetic (64 bits on most workstations). The actual number of bytes used in the internal storage of these data types depends on the machine being used.
The printf function can be instructed to print integers, floats and strings properly. The general syntax is
printf( "format", variables );
where "format" specifies the converstion specification and variables is a list of quantities to print. Some useful formats are
%.ndinteger (optional n = number of columns; if 0, pad with zeroes)
%m.nffloat or double (optional m = number of columns,
n = number of decimal places)
%nsstring (optional n = number of columns)
%c character
\n \t to introduce new line or tab
\gring the bell (``beep'') on the terminal
--------------------------------------...
3. Loops
Most real programs contain some construct that loops within the program, performing repetitive actions on a stream of data or a region of memory. There are several ways to loop in C. Two of the most common are the while loop:
while (expression)
{
...block of statements to execute...
}
and the for loop:
for (expression_1; expression_2; expression_3)
{
...block of statements to execute...
}
The while loop continues to loop until the conditional expression becomes false.
Reply:you can only get help from online but totally you can not get total knowledge of any programming language.but you can try from the link.
Reply:Google them
Reply:http://cprogramming.com/
is the best website for learning c and c++ online
Reply:I dont think u will be able to find complete free c language tutorials or complete project help online. But i suggest that you should try googling for programming language forums or search boardreader.com for c forums. Join the forum and start learning c.. Then u can ask any difficulty at the forum where people will answer your questions. You will find some good c language questions here http://previouspapers.blogspot.com/2008/... These are quite good for various placement papers and technical interviews or common project related questions asked by teachers.
Also you will find studying c language easier when u study from some book from your library and ask the problems on the forums.. good luck.. hope i helped..
Reply:http://www.universalclass.com/i/crn/8213...
Go on this sit.It will teach from basics to advanced
Reply:I learned C at 12 with LSL. It's in a game called Second Life, it's event-driven, and it's very similar to C.
http://www.secondlife.com/
easter cards
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment