C is a general-purpose, imperative computer programming language.
It supports structured programming, lexical variable scope and recursion, and has static type system.
Now we start to write the first program using C.
Firstly, open your text editor and create new file, called hello.c
Let's write this code
#include <stdio.h>
int main() {
printf("Hello C\n");
return 0;
}
Save this file.
Now open your Terminal and compile this file.
In C language if you write a line of code we must write semicolon (;) at the end of code.
Here is the syntax rule:
syntax_code;
The code above generates the following result.
Run your editor and type in the following program.
#include <stdio.h>
int main(void)
{
printf("Hello world!");
return 0;
}
When you've entered the source code, save the program as hello.c.
The following code adds comments to the code above.
/* Simple C Program - Displaying a String*/ #include// This is a preprocessor directive int main(void) // This identifies the function main() { // This marks the beginning of main() printf("Hello world!"); // This line outputs a quotation return 0; // This returns control to the operating system } // This marks the end of main()
//
starts the comment line.
Using comments can be a very useful way of explaining what's going on in the program.
You can place comments wherever you want in your program, and you can use them to explain the general objectives of the code.
The code above generates the following result.
Look at the following line of code:
#include// This is a preprocessor directive
The symbol #
indicates this is a preprocessing directive,
which is an instruction to your compiler to do
something before compiling the source code.