Skip to main content

LANGUAGE C

 is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972.
In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard.
The UNIX operating system, the C compiler, and essentially all UNIX application programs have been written in C. C has now become a widely used professional language for various reasons −
  • Easy to learn
  • Structured language
  • It produces efficient programs
  • It can handle low-level activities
  • It can be compiled on a variety of computer platforms

Facts about C

  • C was invented to write an operating system called UNIX.
  • C is a successor of B language which was introduced around the early 1970s.
  • The language was formalized in 1988 by the American National Standard Institute (ANSI).
  • The UNIX OS was totally written in C.
  • Today C is the most widely used and popular System Programming Language.
  • Most of the state-of-the-art software have been implemented using C.
  • Today's most popular Linux OS and RDBMS MySQL have been written in C.

Why use C?

C was initially used for system development work, particularly the programs that make-up the operating system. C was adopted as a system development language because it produces code that runs nearly as fast as the code written in assembly language. Some examples of the use of C might be −
  • Operating Systems
  • Language Compilers
  • Assemblers
  • Text Editors
  • Print Spoolers
  • Network Drivers
  • Modern Programs
  • Databases
  • Language Interpreters
  • Utilities

C Programs

A C program can vary from 3 lines to millions of lines and it should be written into one or more text files with extension ".c"; for example, hello.c. You can use "vi""vim" or any other text editor to write your C program into a file.
This tutorial assumes that you know how to edit a text file and how to write source code inside a program file.

cal Environment Setup

If you want to set up your environment for C programming language, you need the following two software tools available on your computer, (a) Text Editor and (b) The C Compiler.

Text Editor

This will be used to type your program. Examples of few a editors include Windows Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi.
The name and version of text editors can vary on different operating systems. For example, Notepad will be used on Windows, and vim or vi can be used on windows as well as on Linux or UNIX.
The files you create with your editor are called the source files and they contain the program source codes. The source files for C programs are typically named with the extension ".c".
Before starting your programming, make sure you have one text editor in place and you have enough experience to write a computer program, save it in a file, compile it and finally execute it.

The C Compiler

The source code written in source file is the human readable source for your program. It needs to be "compiled", into machine language so that your CPU can actually execute the program as per the instructions given.
The compiler compiles the source codes into final executable programs. The most frequently used and free available compiler is the GNU C/C++ compiler, otherwise you can have compilers either from HP or Solaris if you have the respective operating systems.
The following section explains how to install GNU C/C++ compiler on various OS. We keep mentioning C/C++ together because GNU gcc compiler works for both C and C++ programming languages.

Installation on UNIX/Linux

If you are using Linux or UNIX, then check whether GCC is installed on your system by entering the following command from the command line −
$ gcc -v
If you have GNU compiler installed on your machine, then it should print a message as follows −
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr .......
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)
If GCC is not installed, then you will have to install it yourself using the detailed instructions available at http://gcc.gnu.org/install/
This tutorial has been written based on Linux and all the given examples have been compiled on the Cent OS flavor of the Linux system.

Installation on Mac OS

If you use Mac OS X, the easiest way to obtain GCC is to download the Xcode development environment from Apple's web site and follow the simple installation instructions. Once you have Xcode setup, you will be able to use GNU compiler for C/C++.
Xcode is currently available at developer.apple.com/technologies/tools/.

Installation on Windows

To install GCC on Windows, you need to install MinGW. To install MinGW, go to the MinGW homepage, www.mingw.org, and follow the link to the MinGW download page. Download the latest version of the MinGW installation program, which should be named MinGW-<version>.exe.
While installing Min GW, at a minimum, you must install gcc-core, gcc-g++, binutils, and the MinGW runtime, but you may wish to install more.
Add the bin subdirectory of your MinGW installation to your PATHenvironment variable, so that you can specify these tools on the command line by their simple names.
After the installation is complete, you will be able to run gcc, g++, ar, ranlib, dlltool.e we study the basic building blocks of the C programming language, let us look at a bare minimum C program structure so that we can take it as a reference in the upcoming chapters.

Hello World Example

A C program basically consists of the following parts −
  • Preprocessor Commands
  • Functions
  • Variables
  • Statements & Expressions
  • Comments
Let us look at a simple code that would print the words "Hello World" −
#include <stdio.h>

int main() {
   /* my first program in C */
   printf("Hello, World! \n");
   
   return 0;
}
Let us take a look at the various parts of the above program −
  • The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation.
  • The next line int main() is the main function where the program execution begins.
  • The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program.
  • The next line printf(...) is another function available in C which causes the message "Hello, World!" to be displayed on the screen.
  • The next line return 0; terminates the main() function and returns the value 0.

Compile and Execute C Program

Let us see how to save the source code in a file, and how to compile and run it. Following are the simple steps −
  • Open a text editor and add the above-mentioned code.
  • Save the file as hello.c
  • Open a command prompt and go to the directory where you have saved the file.
  • Type gcc hello.c and press enter to compile your code.
  • If there are no errors in your code, the command prompt will take you to the next line and would generate a.out executable file.
  • Now, type a.out to execute your program.
  • You will see the output "Hello World" printed on the screen.
$ gcc hello.c
$ ./a.out
Hello, World!
Make sure the gcc compiler is in your path and that you are running it in the directory containing the source file hello.c.
e we study the basic building blocks of the C programming language, let us look at a bare minimum C program structure so that we can take it as a reference in the upcoming chapters.

Hello World Example

A C program basically consists of the following parts −
  • Preprocessor Commands
  • Functions
  • Variables
  • Statements & Expressions
  • Comments
Let us look at a simple code that would print the words "Hello World" −
#include <stdio.h>

int main() {
   /* my first program in C */
   printf("Hello, World! \n");
   
   return 0;
}
Let us take a look at the various parts of the above program −
  • The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation.
  • The next line int main() is the main function where the program execution begins.
  • The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program.
  • The next line printf(...) is another function available in C which causes the message "Hello, World!" to be displayed on the screen.
  • The next line return 0; terminates the main() function and returns the value 0.

Compile and Execute C Program

Let us see how to save the source code in a file, and how to compile and run it. Following are the simple steps −
  • Open a text editor and add the above-mentioned code.
  • Save the file as hello.c
  • Open a command prompt and go to the directory where you have saved the file.
  • Type gcc hello.c and press enter to compile your code.
  • If there are no errors in your code, the command prompt will take you to the next line and would generate a.out executable file.
  • Now, type a.out to execute your program.
  • You will see the output "Hello World" printed on the screen.
Make sure the gcc compiler is in your path and that you are running it in the directory containing the source file hello.c.e we study the basic building blocks of the C programming language, let us look at a bare minimum C program structure so that we can take it as a reference in the upcoming chapters.

Hello World Example

A C program basically consists of the following parts −
  • Preprocessor Commands
  • Functions
  • Variables
  • Statements & Expressions
  • Comments
Let us look at a simple code that would print the words "Hello World" −
#include <stdio.h>

int main() {
   /* my first program in C */
   printf("Hello, World! \n");
   
   return 0;
}
Let us take a look at the various parts of the above program −
  • The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation.
  • The next line int main() is the main function where the program execution begins.
  • The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program.
  • The next line printf(...) is another function available in C which causes the message "Hello, World!" to be displayed on the screen.
  • The next line return 0; terminates the main() function and returns the value 0.

Compile and Execute C Program

Let us see how to save the source code in a file, and how to compile and run it. Following are the simple steps −
  • Open a text editor and add the above-mentioned code.
  • Save the file as hello.c
  • Open a command prompt and go to the directory where you have saved the file.
  • Type gcc hello.c and press enter to compile your code.
  • If there are no errors in your code, the command prompt will take you to the next line and would generate a.out executable file.
  • Now, type a.out to execute your program.
  • You will see the output "Hello World" printed on the screen.
$ gcc hello.c
$ ./a.out
Hello, World!
Make sure the gcc compiler is in your path and that you are running it in the directory containing the source file hello.cou have seen the basic structure of a C program, so it will be easy to understand other basic building blocks of the C programming language.

Tokens in C

A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol. For example, the following C statement consists of five tokens −
printf("Hello, World! \n");
The individual tokens are −
printf
(
"Hello, World! \n"
)
;

Semicolons

In a C program, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity.
Given below are two different statements −
printf("Hello, World! \n");
return 0;

Comments

Comments are like helping text in your C program and they are ignored by the compiler. They start with /* and terminate with the characters */ as shown below −
/* my first program in C */
You cannot have comments within comments and they do not occur within a string or character literals.

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 does not allow punctuation characters such as @, $, and % within identifiers. C is a case-sensitive programming language. Thus, Manpowerand manpower are two different identifiers in C. Here are some examples of acceptable identifiers −
mohd       zara    abc   move_name  a_123
myname50   _temp   j     a23b9      retVal

Keywords

The following list shows the reserved words in C. These reserved words may not be used as constants or variables or any other identifier names.
autoelselongswitch
breakenumregistertypedef
caseexternreturnunion
charfloatshortunsigned
constforsignedvoid
continuegotosizeofvolatile
defaultifstaticwhile
dointstruct_Packed
double

Whitespace in C

A line containing only whitespace, possibly with a comment, is known as a blank line, and a C compiler totally ignores it.
Whitespace is the term used in C to describe blanks, tabs, newline characters and comments. Whitespace separates one part of a statement from another and enables the compiler to identify where one element in a statement, such as int, ends and the next element begins. Therefore, in the following statement −
int age;
there must be at least one whitespace character (usually a space) between int and age for the compiler to be able to distinguish them. On the other hand, in the following statement −
f.

 

 

Comments

Popular posts from this blog

THE ADVANTAGES OF KAALI MIRCH

काली मिर्च के फायदे (द अडवांटागेस ऑफ़ काली)  काली मिर्च एक उत्तम ओषदि है  1. गैस की शिकायत : एक कप पानी में आधे निम्बू का रस ,आधा चमच काली मिर्च का चूर्ण और आधा चमच काला नमक मिलकर सेवन करे। गैस की शिकायत दूर हो जायेगी।  2 . बदहजमी : एक निम्बू काट दो फाकें करे और उस पर पीसी हुई काली मिर्च और काला नमक लगाकर चूसे। इससे बदहजमी दूर हो जायेगी।  3. खांसी : आधा चमच षद में दो चुटकी पीससि हुई काली मिर्च मिलाकर दो तीन बार दिन मे चाटे >खांसी बंद हो जाएगी।  4. जुखाम : चार पांच दाने काली मिर्च ,10 तुलसी के पटे ,डोलोंग ,एक कतरन अदरक ,एक इलायची को मिक्स करकर पानी में पकाले और दूद मिलाकर चाय की तरह तीन चार बार पिए। जुखाम से राहत मिलेगी और यदि ज्वर होगा तो उत्तर जाएगा।  5. रतोंधी : काली मिर्च को षड और दही में घिसकर आँखों में अंजन करे। रतोंधी खत्म हो जायेगी।  6. पेशिच : काली मिर्च के बारीक चूर्ण के षड मिलाकर चांटे और ऊपर से छाछ पिए। पेशिच बंद हो जायेगी।  7. मलेरिया : कालीमिर्च का चूर्ण तुलसी के रस और षड में चाटने से मलेरिया उत्तर जाएगा।  8. मसूड़ों का दर्द : काली मि

THE ADVANTAGES OF FITKARI...

                        फिटकरी फिटकरी एक घरेलू औषदि है। यह बहुत ही महत्त्वपूर्ण हैं अंत: हर समय फिटकरी उपलब्ध रहना आवश्यक है।                                        फिटकरी  के गुण  1. दांत दर्द में लाभकारी -फिटकरी और रीठे की गुठली का चूर्ण दांतो पे मले। लाभ होगा।  2. पायरिया -5 ग्राम फिटकरी का चूर्ण बनाकर जामुन की लकड़ी के कोयले को बारीक पीसकर मिलाये और मिश्रण को दांतो पर मले।  3. कुष्ठ रोग -100 ग्राम फिटकरी पीसकर भस्म बनाये और एक चमच्च शहद में गाजर तथा मूली का रस मिलाकर 2 रति फिटकरी भस्म के प्रतिदिन सेवन करे।  4. आँख के रोहे -यह बहुत कष्ट कारक रोग हैं। इस रोग में फिटकरी लाभकारी औषदि हैं। 10 ग्राम फिटकरी और 10 ग्राम सुहागा और 3 ग्राम कलमी शोरा पीसकर मिला ले। लाभ होगा  5 . पीलिया - 10 ग्राम फिटकरी पीसकर पीस क्र कम से कम 20 भाग करे और एक -एक भाग दिन में तीन बार गाय के दूध के साथ सेवन करे। पीलिया रोग मैं फायदेमंद है।  6 . जखम होने पर -यदि किसी प्रकार आपको चोट लगे और हल्का फुल्का जख़्म हो गया है तो फिटकरी पीसकर कटे हुए भाग पर बुरक दे। जख्म को पकने से बचाव होगा और जख

THE CAPTAIN OF INDIAN WOMEN CRICKET TEAM....

तेलंगाना सरकार ने इंडियन वीमेन क्रिकेट टीम के कप्तान को दिए 1 करोड़ और 1 प्लाट भी दिया। वैसे तो आप सब ये खबरे सुनते नहीं और अगर यही खबर किसी इंडियन मेन क्रिकेट टीम के बारे में होती तो आप इस खबर में ज्यादा दिचस्पी लेते और इसके बारे मैं चर्चा करते। जैसे अगर यही खबर इंडियन कप्तान विराट कोहली के बारे में होती तो ये ख़बर बहुत ट्रेंड करती। दोस्तों अगर हम लड़को की तरह लड़कियों की शिक्षा के ऊपर ध्यान देते हैं तो लड़किया भी हमारे देश का नाम रोशन करेंगी। plz दोस्तों इनको भी सपोर्ट कीजिये। आज हम आपको इंडियन वीमेन क्रिकेट टीम के कप्तान मिताली राज के बारे में बताने वाले हैं। आज आप सबके के सपोर्ट के कारण ये इतनी ट्रेंड और अच्छा अच्छा खेल रही हैं। इसी कारण तेलंगाना सरकार ने इंडियन वीमेन कप्तान मिताली राज को 1 करोड़ और 1 प्लाट भी इनके खेल में अच्छा पर्दशन करने के कारण दिया। अगर यह काम हमारा समाज पहले कर देता तो आज वीमेन इंडियन क्रिकेट टीम फाइनल मैच में जीत जाती। यही काम पंजाब की सरकार ने हरमन प्रीत के खेल से खुश होकर उनके सम्मान मे दिये। हमनप्रीत कौर को पंजाब की सरकार ने 5 लाख और एक सरकारी नौ