C can be used to do just about anything. Some tasks require more work than others, which is why people are using C++ more and more for projects that used to be done in C. It is good to know both languages, however. Old projects may be in C and too difficult to translate to C++, or not worth the time. In that case it is important to know C for maintenance purposes. Knowing C also provides a good foundation to learn C++. There are some things the C++ standard library does not do but the C library does. Rather than reinventing the wheel, it makes sense to use both C and C++ libraries and ideas next to each other.
C programs start with headers. They usually contain data definitions: for example, program constants, macros, prototypes, global variables, etc. but not actual logic. The main block in a C program is the main() function which is a system function including the logic flow of the C program. Inside the main(), all the local variables are first declared. Next comes the function calls and all the logic of the program.
C programs usually have several pieces that fit together to make a program. Usually you will have a group of source code files that are compiled separately, then linked together into a single executable file. Each source code file will have a header file that describes its contents.
Your source code files contain all your code that actually does stuff, the program logic. Multiple files are used for all but the shortest of programs because it just isn't practical to have a single source code file with thousands or even millions of lines of code. It's too difficult to maintain. Usually, similar functions are grouped together in a single file. For example, one file may contain your program's code for loading and saving its data to disk. Another file may contain the code for displaying the main window. The header files usually contain little or no program logic.
Functions are the cornerstone of C programming. Functions are cohesive blocks of code that perform common tasks. Code reuse is an important programming concept, and functions allow you, the programmer, to achieve this. Rather than typing out the same task a thousand times, you can put it in a function and use that function over and over again. Therefore, program size becomes smaller.
Another Facts is that C uses pointers extensively. It uses them freely than any other Programming Language. Pointers are variables which store the address of other variables. Using pointers U can literaly point to any addressing location of your system.
This is an example of a C program.
/* Include the Standard C functions for input and output */ #include <stdio.h>
/* This is the main function, where the program starts running */ int main (void) {
/* Display a short message to the user */ printf ("I charge thee. Speak! \n"); /* Program is done now, return to the operating system */ return 0;}
Here's another one..
/* Include the Standard C functions for input and output */ #include <stdio.h>
/* This is the main function, where the program starts running */ void main() {
/* Declare variable of integer type and a pointer variable and initialise the variable with the value of 10*/ int var=10,*vptr; /* Initialise the pointer with address of variable*/ vptr=&var; /* Display the containt of each variable */ printf ("%d",var); printf ("%u",&var); printf ("%u",vptr); printf ("%d",*vptr);}
That's it for today..