ProDeveloperTutorial.com

Tutorials and Programming Solutions
Menu
  • Shell Scripting
  • System Design
  • Linux System Programming
  • 4g LTE
  • Coding questions
  • C
  • C++
  • DSA
  • GIT
  • 450 DSA Cracker
  • 5G NR
  • O-RAN

Chapter 1: C language Introduction

prodevelopertutorial July 1, 2018

In this chapter you will learn about:

  1. Introduction to C Language.
  2. Features of C language.
  3. Disadvantages of C language.
  4. C program structure.
  5. C Comments.
  6. Important header files.
  7. C programming Rules.

 

Introduction to C Language:

  1. C is a Procedural programming language. This means there will a series of statements inside a procedure (function) that needs to be carried out.
  2. C was developed by Dennis Ritchie at Bell labs in 1973.
  3. C11 is the latest stable version released in 2011 December. This is supported by all major C compilers.
  4. Unix and Linux operating system is written using C language.
  5. C is a middle level programming language.
  6. Many other programming languages like Java, Go, C# have been heavily influenced by C.
  7. C programming allows static and dynamic memory management.
  8. During 1970 and 1980 many versions of C have been implemented. Hence in 1989 ANSI C was introduced and was later accepted by ISO in 1990.
  9. All the C source file will be saved as .c file extension. Example “helloWorld.c”
  10. All the C header file will be saved as .h file extension. Example “stdio.h”

 

Features of C language:

  1. Robust
  2. Portable
  3. Fast
  4. Simple and easy to learn
  5. Extensible

 

Disadvantages of C language:

  1. Not an object-oriented language.
  2. Some code needs to be recompiled when running on a different machine.
  3. No constructors and destructors
  4. There is no runtime checking. An error is known only after execution of a c program.
  5. There is no strict type checking. In C programming language we can send integer value for a float data type.
  6. No data security is available.

C is able to access low-level memory of hardware. This helps a programmer to develop efficient code. Hence C language is called as a middle-level programming language.

 

 

C program structure:

 

A simple C program should contain following lines.

#include<stdio.h>

int main()

{
	printf("Hello World \n");
	return 0;
}

Program  Explanation:

The first line “#include” is called as pre-processor directive. “stdio.h” is called a header file. This header file has declarations about standard input and output functions.

Next line is “int main()“. main() is the starting point of any c program. There is a return type specifies “int”, that informs the compiler that the function returns a value is of type int.

 

Next is opening brace ‘{‘, indicating the starting of function main().

Next line is a “printf()” function. This is used to display the output to the standard console. Note that every statement inside a function has ended with a semicolon. This informs the compiler that the statement has ended. And semicolon is mandatory to terminate a statement.

 

Next is “return 0;“. This will return the program execution back to the called function. In this case compiler. In C, returning value 0 indicates the program completed without any issues.

 

Last line is closing brace ‘}‘, indicating the end of function main().

 

To compile a C program in Linux use the following command:

 

gcc hello.c –o hello.o

To run the executed program, use below command:

./hello.o

 

C Comments:

Comments provide effective ways of knowing the functionality of a function. It is always a good practice to include comments in the beginning of a function with a short description of what it does.

The part written inside comments will be ignored by the compiler and the comments will be stripped off while compiling the program.

 

C supports 2 types of comments:

 

  1. Single line comment:

// This is a single line comment

 

  1. Multiline comment:

 

/* This is

an example of

multiline comment

*/

 

Example for comments:

 

#include<stdio.h>

int main()

{

	int num = 1; // integer variable

	/* Multi line comment

	num = num + 1;

	Above code will not be executed,

	as it is in comment

	*/

	return 0;

}

 

 

 

Important header files.

 

stdio.h : Provides input, output functions like printf(), scanf().

conio.h : Console input and output, provides functions like clrscr(), getch().

alloc.h : Provides memory allocation functions like malloc(), calloc(), free().

math.h : Provides math related functions like abs(), squrt().

string.h : Provides string related functions like strcpy(), strcat().

assert.h : Provides macros like assert(int).

 

 

C programming Rules:

 

While writing any C program, we must follow below rules:

    1. Every program should have a main() to run and generate an output.
    2. All the statements should be terminated by a semicolon.
    3. If the programmer has written only semicolon in a line, then it is treated as an empty statement.

Ex:

;

  1. All the function names, variable names should be written in lower case, Upper case is used for symbolic constants.
  2. Every opening braces should have an closing braces.

 

List Of Tutorials available in this website:

C Programming 20+ ChaptersC++ Programming 80+ Chapters
100+ Solved Coding QuestionsData Structures and Algorithms 85+ Chapters
System design 20+ ChaptersShell Scripting 12 Chapters
4g LTE 60+ ChaptersMost Frequently asked Coding questions
5G NR 50+ ChaptersLinux System Programming 20+ chapters

 

Share
Email
Tweet
Linkedin
Reddit
Stumble
Pinterest
Prev Article
Next Article

About The Author

prodevelopertutorial

Follow this blog to learn more about C, C++, Linux, Competitive Programming concepts, Data Structures.

One Response

  1. Nandini
    Log in to Reply

    Can i get C and C++ as a pdf format

    September 1, 2020

Leave a Reply Cancel Reply

You must be logged in to post a comment.

ProDeveloperTutorial.com

Tutorials and Programming Solutions
Copyright © 2023 ProDeveloperTutorial.com
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT