Subscribe Us

Learn C programming - C programming for beginners - smart duniya

 

C programming


C file :

All C programs are written in text files with the extension ".c" for example hello.C  . You can use text editor to write your C program to a file. I assume you know how to edit a text file and write programming instructions inside a program file.

 C compiler :

When you write a program in C language, to run that program you need to compile that program using a C compiler which converts your program into a language that can be understood by a computer. This is called Machine language. So before proceeding, make sure that C compiler is available on your computer. you can download a c-compiler according to your system . Many C compiler are available for free like Dev++ , Turbo C++ , Code Blocks.

 

Run your first program in c program :

 Hello world! A simple program that displays "Hello, World!" On screen. Since, it is a very common program, it is used to refer to the basic syntax of any programming language. This program is often used by a beginner to introduce programming languages. Let's start .



Write this code on any text editor . If  you use ( DEV C++ ) or other IDE . it helps you to write ,compile and  run code easily. After writing this code  save this code with ' .c ' extension . 

Then Compile and run this Code. You will get a screen and display ' Hello World ! ". 




 

Why Write This Code

1. # Included   is a preprocessor command. This command tells the compiler to include the contents of the <stdio.h> (standard input and output) file in the programmer. It’s called header file .

2. The <Stdio.h> header-file store functions such as scanf () and printf () to take input and give output.

If you use the printf () function without writing, the # included program will not be compiled.

3. Main() Function execute the program.

4. A library function for sending formatted output to the printf () screen. In this program, Printf () shows Hello, World! Screen text.

5. getchar() is  used  for hold the screen. Other wise the screen will be exit after print output. getchar() hold the screen until you press any character. You can use ‘return 0’ in spite of getchar()

The ‘return 0 ‘statement is work same as the ‘getchar()’ in  the program. Simply put, the program ends with this statement.

 

Why We Use Semicolon; in c program :

Semicolon “ ; “  tell the compiler that the line is end. The absence of a semicolon at the end of any statement, this statement is not yet finished and it will add a subsequent statement, which will confuse the compiler to assume that the syntax may lead to error.

Comments

Comments are simple text of the C program that is not compiled by the compiler. We write comments to better understand the program. Although comment writing is not mandatory, it is recommended to make your program more descriptive. This makes the code more readable.

There are two comments so we can write comments.

1.     1.  Single line comment

// this is single line comment

2.      2. Multiline comment

/* This is

Multi line Comment
 In C programming . */

 

Let’s go to a program to understand the comment in real .




Identifiers :

In C language identifiers are the names given to variables, constants, functions and user-define data. These identifier are defined against a set of rules.

An Identifier can only have alphanumeric characters(a-z , A-Z , 0–9) and underscore( _ ).

The first character of an identifier can only contain alphabet(a-z , A-Z) or underscore ( _ ).

Identifiers are also case sensitive in C. For example name and Name are two different identifiers in C.

Keywords are not allowed to be used as Identifiers.

No special characters, such as semicolon, period, white spaces, slash or comma are permitted to be used in or as Identifier.

Hope you understand if you face any problem comment below ,will try to help you.

 

Don’t forget to Subscribe our Blog to get update. Just put your email on subscribe box and hit subscribe button , next verify your email , it will be done.

You will get every single post when we will upload in Smartduniya.


Also learn this post :


How to write comment in C ?

How to write keyword, identifires in C ?

How to write Printf() function in C ?

Post a Comment

0 Comments