Learn C Programming Language
Create and run a simple C program
Printing a line of text
C uses some notations that may appear strange to people who have not programmed computers. We begin by considering a simple C program. Our first example prints a line of text.
1 #include <stdio.h>
2 // function main begins program execution
3 int main( void ) {
4 printf( "Welcome to C!\n" );
5 } // end function main
Output :
Welcome to C!
#include Preprocessor Directive
#include <stdio.h>
Line 1 is a directive to the C preprocessor. Lines beginning with # are processed by the preprocessor before compilation. Line 1 tells the preprocessor to include the contents of the standard input/output header ( <stdio.h>) in the program.
Comments
// function main begins program execution
Line 2 begin with //, indicating that line is a comment. Comments programs and improve program readability and are ignored by the C compiler and do not cause any machine-language object code to be generated. You can also use /*…*/ multi-line comments.
The main Function
int main( void )
Line 3 The Main is a part of every C program that contain one or more functions, one of which must be main where every program in C begins executing. The keyword int to the left of main indicates that main “returns” an integer (whole-number) value.
An Output Statement
printf( "Welcome to C!\n" );
Line 4 Printf( "Welcome to C!\n" ); instructs the computer to perform an action, namely to print on the screen the string of characters marked by the quotation marks. The “f” stands for “formatted”), its argument within the parentheses and the semicolon (;), is called a statement.
Ads Right