WHEN YOU HAVE ANY DOUBT

  • This is default featured slide 1 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

  • This is default featured slide 2 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

  • This is default featured slide 3 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

  • This is default featured slide 4 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

  • This is default featured slide 5 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

Basic syntax of C

'C' Basic Syntax


Basic syntax of a simple C program contains header files, main() function and then program code. Here is the basic syntax of a simple and smallest C program:


Every C program must contains a function called main(), because program execution starts from main(). For example, here is the simple and smallest C program, which would print "Hello Compiler" on the output screen:



Output of simple program is:



Tokens in C

In C, a token is either a keyword or a constant or a string constant or a symbol or an identifier. And a C program consists of various tokens, depends on, how long the program is. Let's look at the following example, here the statement consists of total five tokens:

Semicolons in C

In C programming, a semicolon is used to terminate a statement. Semicolon in C also called as statement terminator because each individual statement must be ended with a statement terminator or semicolon. This tells the compiler that this statement is completed. And it indicates that the end of one logical entity or statements. If semicolon is not placed at the end of any statements, then the program will not compile, generates error message on compilation. Let's look at the following example, here there are two different statements terminated by the semicolon each:


Comments in C

In C Programming, comments are just like a helping text in your C program. They are ignored by the compiler. Comments are very useful in reviewing the code. Since at the time of reviewing the code, given comments helps a lot for a programmer. As comments, programmer can add useful information or reminder about some line of code or something for other purposes.
In C language, there are the following two types of comments:
  • Single-line comments - starts from // to the end of line
  • Multi-line comments - starts from /* and ends with */
Here is an example program, demonstrates both, the single-line comments and the multi-line comments:

Here is the sample output of this C program. You will see, only "Welcome to codescracker.com" will be printed on the output screen. And as already told, all the comments are ignored by the compiler. Because comments can only be read by the programmer.

Identifiers in C

In C programming, an identifier is the name that is used to identify a variables, functions, or any other user-defined terms. An identifier can start with letters (A to Z) or (a to z) or an underscore ( _ ) followed by zero or more letters, underscores, and digits (0 to 9)
C does not allows punctuation characters (special characters) like @, $, and % within identifiers. Since C programming is a case sensitive programming language. Thus, Total and total are the two different identifiers in C. Here the following table lists some valid identifiers :
Here is an example program. Just concentrate on this. This program also illustrates that the num and Num or name and Name are different-different identifiers:

Here is the sample run of the above C program:

C Keywords

Keywords are the reserved words having special meaning. Here the following table lists the C keywords:

Whitespaces in C

In C programming, any line containing only whitespace, like with a comment, is known as a blank line, and the C compiler completely ignores it. Whitespace is a term used in C programming that describe the blanks, tabs, newline characters and the comments. Whitespace separates one part of a statement from another part of a statement and it enables the compiler to identify that where one element in a statement, like int, ends and the next element begins. Here this statement:

There must be at least one whitespace character (generally a space) between int (data type) and sum (variable) for a compiler to be able to distinguish them. If you will not insert a whitespace between them then it will become intsum and will be treated as an identifier.

Share:

Structure of C Program

"C" Program Structure


Program structure of a simple C program contains header files, main() function, and then program code. You will find easy in understanding the program structure of any simple C program. Let's start with C Hello World program which would print Hello World! on the output screen.

C Program Structure Example

Here is an example program, showing the general structure of a simple C program:


The output of above program is:



Above Example Explained

Here is the explanation of each line of the above program (Read carefully all the line):
  • Multi-line Comment - The first three line is multi-line comment, which will ignored by the compiler.
  • Preprocessor Command - The next line of the C program #include<stdio.h>; is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation to handle the standard input and output functions like printf(), scanf() etc like functions. printf() is used to put message on the output screen given by the programmer, and scanf() is used to scan to get the material which was entered by the user.
  • Preprocessor Command - The second line of the c program #include<conio.h> is also a preprocessor command, which tells a C compiler to include<conio.h> file before going to actual compilation to handle the getch() and clrscr() etc like functions.
  • Function - The next line void main() is a function from where the program execution begins. void tells the program to not return any values and main is that from where the program execution begins/starts.
  • Single-line Comment - The next line is single-line comment which starts from //.
  • Function - The next line clrscr() is a function which is used to clear the output screen since sometime in compiler like turboC++, there is already present their message or something other on the output screen which was set by the compiler's developer, and sometime we run our program second time or second program then the previous output is remain on screen and this will create some confusion so it is best practice to first clear the output screen to avoid confusion.
  • Multi-line Comment - The next line is also a multi-line comments, starts from /* and ends with */ which is ignored by the C compiler and it has been put to add the additional comments in program. So such lines are called as comments in the program.
  • Function - The next line printf(...) is another function available in C that causes the message "Hello, World!" to be displayed on screen since its work is to put message on the output screen according to the programmer.
  • Function - The next line getch(); getch() is used to hold the output screen in turboC++ like compiler if you will not use this function at the last of your program then after pressing run button your output screen comes and closed within fraction of seconds and you can't be able to watch your output. When you use getch() function, then your output screen will hold after all programming task will get finished and until you press any character, after pressing any character, your output will close and get back to your program .







Share:

Tutorials of C programming language

C TUTORIAL

This tutorial will teach you all about C programming from very basic for beginner to advance.

What is C ?

C is a programming language which was invented, first implemented by Dennis Ritchie on DEC PDP-11, used UNIX operating system.

C is a Middle-Level Language

C language is often called as a middle-level computer language. This doesn't mean that C is something weaker than other language. For your knowledge, C is much faster than other languages. You can use C to make your program running more faster.

C is a Structured Language

C is also referred as a structured language.

C is a Programmer's Language

C programming language was created, influenced, and field-tested by working programmers. C gives the programmer what the programmer wants: few restrictions, few complaints, stand-alone functions, block structure, and a compact set of keywords. By using C programming language, you can nearly achieve the efficiency of assembly code that combined with the structure of Pascal or Modula-2.
It is no wonder that C has now become the universal language of programmers around the world.

here,
First program on C language:


The output of above program is:

Let's look at one more C program


The output of above program is:


You will learn all about C programming in this tutorial series.

Audience

This tutorial of C programming is designed and developed to all those C lover, who wants to practice with a lot of codes. Therefore you can follow this tutorial to learn C along with a lot of C codes with its respective output.
We have included a lot of C programming codes where required in each and every chapter.

Prerequisites

Before start learning C programming, you must have some basic computer skills.
If have already some knowledge about how to program, then you will feel very easy to learn C.






Share:

Popular Posts

Recent Posts