position: fixed; top: auto !important; margin-left: 112px;

Basic C Program

Trust me learning C language is the best decision ever in your life. Skills you need to be the best computer programmer in this world starts with C Language. It is very easy to learn and understand the concepts. We will guide you through each and every concept step by step. At the end of each article, try to solve the quiz so that you can test your understanding of the concept. Okay, So let's begin with the very basic C program...

Most programming languages like C++, Java adopts syntax of C language. That's why C programming is also called as the mother of all Programming languages.

Basic Syntax

/* Preprocessor Declaration */
main () Function 
{
program statements to be executed.
} 

1) Preprocessor Declaration: This section includes all the necessary libraries required whose functions we use in our program. These libraries are also the C programs which contains functions and make the life of developers easy.

2) main(): main function is the entry point of the program.

Example :-

This basic C program which illustrates the syntax of C language.

/* C First program */

#include <stdio.h>  
#include <conio.h> 

void main()
{  
printf(" hello world c ");  
  
getch();  
} 

Explanation :-

#include <stdio.h>

This is the standard input output library functions. The printf() function is defined in stdio.h .

#include <conio.h>

This is the console input output library functions. The getch() function is defined in conio.h file.

void main()

The main() function is the entry point of every program in c language. The void keyword specifies that it returns no value.

printf()

The printf() function is used to print data on the console.

getch() 

The getch() function is used to hold the screen unless and until the user presses any key like "Enter" or any key. Try removing getch() in the program and see the effect.

Comments

Comments are used to describe the purpose of statements in the program. It is the best practice to include comments every time you write the program. Suppose there is a team of 20 developers in a company which is working on the same project. Then each and every developer should understand what you have written in your code. This is how comments can be useful in live projects.

/* This is a C Comments Statement */

Example:-

/* C First program Comment */

/* C Libraries */
#include <stdio.h>  
#include <conio.h> 

/* Main Function 
void main()
{ 

/* Print the Hello world */ 
printf(" hello world c ");  
  
getch();  
}  

C Identifiers:-

A C identifier is a name used to identify a variable, function, or any other user-defined item. An identifier starts with a letter A to Z, a to z, or an underscore '_' followed by zero or more letters, underscores, and digits (0 to 9). C language does not allow punctuation characters such as @, $, and % within identifiers. C programming is a case-sensitive programming language. Thus, Programming and programming are two different C Identifiers.

abc , _abc , abc_123 are valid tokens
whereas,
$abc,#abc,abc$ are not valid tokens . 

C Token:-

A C program consists of various tokens and token is either a keyword, an identifier, a constant, a string literal, or a symbol. There are 5 tokens in the given example below.

printf                           --> 1st token
(                                --> 2nd token
"Hello world c"                 --> 3rd token
)                                --> 4th token
;                                --> 5th token

Solve the Quiz of Article

1) What do you think programming and Programming are two different Identifiers?
Yes
No

2) Does #include<stdio.h> library includes printf() & scanf() functions?
Yes
No


Previous Next Article







codzify.com


Largest collection of up-to-date tutorials to learn programming languages. We are focused on easy learning. Massive collection of interview questions one may need for preparation.

Social Profile


Linkedin
Twitter
Facebook

Copyright 2018. All rights reserved.