Skip to main content

C Program : Introduction To C Programming Language

C Programming Language

C Program

C programs consist of functions and variables. A function contains statements that specify the computing operations to be done and variables store values used during the computation.


The #include<stdio.h> tells the compiler to include information about the standard input and output library. Stdio.h is a header file and it is included to every c program file at the top of that program.

Features of C Language:-

  • Structured

  • Fast and Efficient

  • Easy to Extend

  • Portable

  • Function Rich Libraries

  • Modularity


C is a robust language which has a rich set of built-in functions, operators which make it code highly efficient.


It is also an extensible language because it continuously adds the library functions supported by the c library for various extra features.


C is a highly portable language; it means that programs once were written can be executed on another machine with little or no change.


C programs are efficient and fast because the use  a variety of data types, functions and operators. 


The program is a collection of functions and it allows the user to create his own function and add it to the c library. It provides code reusability so we can call the function within the function.


This language provides Dynamic Allocation of memory, to allocate memory during the run time.

Syntax of C Program:-


#include<stdio.h>

#include<conio.h>

return_type main()

{

   //code body of a program  or statements.

  return return_type;

}


#include, include the information about the standard library. The conio.h is also a header file which is used for the console input and output function.


The return_type could be int, void, double, char, float. But generally  we use int of void for return type. 


If we declared the main function to return int. It  means, return value will be 0 (zero) or 1.


When the program compiled and executed successfully, we returned 0 else 1. If the main function returns 1 to abort the program execution.


A main function is defined that receives no argument values. All the statements of main function are included in curly braces.


Main function uses a library function printf() to display the result on the screen of a computer. 

Simple example:-


C program to print a message “Learning C Programming Language” on screen.


#include<stdio.h>

#include<conio.h>

void main()

{

  printf(“Learning C Programming Language”);

}


Output:-

Learning C Programming Language


Explanation:-


In this c program, first included header files for standard input and output. The return type of the main function in this program is void, meaning we do not need to return anything at the end of the main program.


Printf function displays the message on the computer screen. Semicolon is denoted at the end of printf() function completion of the execution of that function.




Write a c program to find the sum of  a=10 and b=35;


#include<stdio.h>

#include<conio.h>

int main()

{

  int sum, a=10, b=35;

  sum= a+b;

  printf(“Sum = %d\n”,sum);

  return 0;

}


Output:-

Sum = 45


Explanation:-


Inside main, variable a and b are initialized and defined as of type int. Sum is declared as of type int.


Additions of a and b are stored in the sum and printf() function is used to display the aggregate.


\n denotes the newline, after the sum of two numbers are displayed the cursor moves to the new line on the computer screen.


At the end of the program return zero, it means the program is executed successfully. 


Comments in C Language:-


There are two ways to denote comments in the c programming:-

  1. /* anything inside */

  2. // (double slash)

If you want to write the multiple lines of comments in a program we use the first method to write comments.


But we do not use multiple lines for commenting, sometimes we need to write only a sentence then we prefer the second.

Example:-

C program to display single comment and multiple line comments in a program


#include<stdio.h>

#include<conio.h>

int main()

{

  int sum, a=10, b=35;

   // a and b are initialized to 10 and 35

  sum= a+b;

  /* sum of a and b are aggregated and

   stored in sum variable */

  printf(“Sum = %d\n”,sum);

  return 0;

}


Output:-

Sum = 45

Data Types in C Language:-

There are three classification of c data types:-

  1. Primitive data types

  2. Derived Data type 

  3. User Defined Data type


Primitive data types

  •  int

  • char 

  • float

  •  char

  •  void

Derived Data type

  • Array

  • String

  • Pointer

User Defined Data type

  • Structure

  • Union

  • typedef

  • enum



Further, int data type is divided into short, int and long int and these are also classified into signed and unsigned data types.


char data type is also divided into signed and unsigned and float is into double float and long double.


The signed data types refer to both positive and negative values of data. But in case of unsigned data types it only refers to the positive values.

Format Specifier in C Language:-

Data Type                 Specifier

int                                %d

char                             %c

float                             %f

double                         %lf

Variables:-

  • Variables are the containers. These are used to store the data in it.

  • Whenever we initialize a variable with some values that values are stored into a variable.

  • Variables also store the address of the other variable in the program.

Example:-

int x, y; 

//Declaration of  two variables x and y of type integer.

x=45;

y=14;

//x stores the value 45 and y stores value 14


  • C variables must  be declared before they are used. Usually at the beginning of the function before any executable statements.

  • A declaration announces the properties of variables, it consists of a type name. The range of the data types depends on the machine architecture.

  • A 16 bits int which lies between -32768 and +32767, a float is typically a 32 bits quantity, which lies between 10^-38 and 10^+38. 


Note:- printf() is not part of the c language, there is no input or output defined in c itself, printf() is just a useful function from the standard library of functions that are normally accessible to c programs. The behaviour of printf is defined in the ANSI standard, however, so its properties should be the same with any compiler and library that conforms to the standard.



Comments

Popular posts from this blog

Fix Breadcrumbs Error And m=1? In Blogger

  Remove Breadcrumbs Errors And ?m=1 Breadcrumb is a small path. It points your location on your site. It also affects the SEO of your website.  Use canonical URL , so: data:blog.url.canonical  instead of data:blog.url. It should work for both desktop and mobile versions. It means the same URL works on both mobile and desktop without producing the ?m=1 or ?m=0. Before this, I am going to tell you what all the portions I will explain and fix your problem. First we will fix Breadcrumbs Error . This is the most dangerous for your website. Second we will remove ?m=1 and ?m=0, tags from our mobile view URL. Remove Breadcrumbs Error :- You should follow the below steps, so that you would fixed this error :- Go to blogger.com Login to blogger with your blogger email id Click on Template Click edit HTML, you have to edit HTML theme code. Press Ctr + F to open a search bar in your HTML theme code. Search for <div class='breadcrumbs' Paste the below code up to </b:loop> ...

Blogger : How To Create Blog Through Blogger & Its Overview

Overview Of Creation Of Blog Now days online learning and earning is very popular. Most of the people is trying to either learn or earn from their home. If you are a writer or story teller, you have interest in writing or reading new thing. So, This is very helpful for you, in this post i will tell you how to create your own blog website and earn money. Step follow to create a blog on blogger:- First you should have a email account and phone number to open or create a blogging account. You have to go to blogger website page, URL of that page is given below, simply you go and click on the URL. Click on the create new blog, after clicking, you have enter the blog name that you want to show to the user and you must choose or set the appropriate your own blog URL. After this process, you will have created your blog. You can handle everything post, pages, layout, inside the setting,you can set the user information and the account information. In the layout you can set layout from the given ...

API : What is an Application Programming Interface

Application Programming Interface API का पूरा नाम "Application Programming Interface" हैं| यह एक software intermediary है जो दो software applications को एक दूसरे से बात करने का कम करता हैं| जैसे कि उद्धरण के लिए Instagram पर आपको message आता है और आप अपने phone पर check कर लेते है API के कारण, क्योंकि API एक माध्यम है आपके फ़ोन में आप किसी भी application से इनफार्मेशन प्राप्त कर पते  हैं| जब आप अपने phone में  कोई  application use करते है तो application internet से जुड़ता है और data को server पर  भेजता है| तब वह server, data को लेता है और translate करता है इस data को , उसके बाद उस data पर जरुरी कार्य करता है और अंतिम में जो translated data है उसे phone पर send करता हैं| तब Application उस data को translate करता है और आपके फ़ोन पर दिखता है readable form में जैसा आप देखना चाहते हैं|  ये जितने भी कार्य है, phone से data को लेना और उसे translate कर के server को send करना और फिर उसे phone पर user के readable form में change करके उसके फ़ोन पर डिस्प्ले करना, ये सब API के मा...