Chapter 1 "C programming"

 Hello guys this is the first chapter of c programming , In this chapter we will learn about basics of c programming ;

Here we go to learn c language,

                Chapter 1 Variable, contest &keywords                  




Variable :-

A Variable is a container which stores a 'value'

Like in kitchen we use containers storing rice ,Dal,Suger etc.

Similarly, To that Variable in c Stores  Value of a constast . Example:

A=3;      //a is assinged"3"

b=4.7;    //b is assigned "4.7"

c='A' ;    //c is assinged "a"

Rules of naming variable in C :-

1. First character must be an alphabet or underscore(_).

2. No commas , blanks allowed 

3.  No special symbol other than (_) allowed.

4. variable names are case sensitive 

We Must create  meaningful variable names in our programs. This enhance raedabibly of our programs.

Ques: What is variable in c ?

Ans:  Variable is basically nothing but the name of a memory location that we use for storing data. We can change the value of a variable in C or any other language, and we can also reuse it multiple times.

Constants:-

An entity Whose value doesn't change is called as a Constant.

A variable is an entity whose can be changed.

Types of Constant 

primary, there are three types of constants

1`.integer constant |=-1,2,6,7

2.real Constant  =32.2,11.1,4.7

3. character constant = 'a','@','$' -------Must be enclosed in single inverted commas-------;

Ques:- What is constants?

Ans:-  A constant is a name given to the variable whose values can't be altered or changed. A constant is very similar to variables in the C programming language, but it can hold only a single variable during the execution of a program.

Difference between variable and constant ?


KeyWords:-

These are reserved words whose meaningis already known to the compiler there are 32 keywords available in C.

auto         double             int           struct    

break         long             else            switch

case          return             enum       typedef        

char         register           extern         union 

const         short              float        unsigned      

continue    signed           for              void 

default      sizeof            goto         volatile        

 do            static              if              while 


Lets, make our first program in c language;

#include<stdio.h>

int main() {

printf("Hello , This is my first program")

return0;

}



Basics Structure of C program

All C programs have to follow a basic structure .

A c program starts with a main function and executes instructions present inside it.

Each instruction is terminated with a semicolon(;)

There are some rules which are applicable to all the c programs;

1. Every program execution starts from main() function.

2. All the statement are termionated with a semicolon.

3. Instruction are case senitive

4. Instructions are executed in the same order in which they are written.

Comments;-

Comments are used to clarify something about the program in plain language. It is a way For us to add notes to our program. There are two types of comments in c. 

1. Single line comment :- //This is comment 

2. Multi-line Comment :-  /* This is a multi line comment*/

***Comments in a c program are not executed and ignored by compiler.***

Compilation And Execution:-

program.c------> C-compiler --------->program.exe

 A compiler is a computer program which converts a C program into machone learning So  that it can be easily undrstood by the computer.

A c program is written in plain text .

This plain text is combination of instructions in a particular sequence. The compiler performes some basic checks and finally converts the program into an executable.

Library function;-

C language has a lot of valuable library function Which is used to carrry out certain tasks. For instance printf functin is used to print values on the screen


printf("This is %d",i);

%d for integers  

%f for real values *****Like decimal values*****

%c for character *****Alphabetical letter******

Types of variables

1. Integer variable ---> int a=3;

2. Real variable --->   int a=7.7; Float a=7.7;****wrong 7.7 is real *****

3.character variable---> char='B';

Receiving input from the user

In order to take input from the user and assign it to a variable, we use scanf function

Syntax for using scanf:

scanf ("%d ",&i);***& is very imporaant****

& is the "address of " operator and it means that the supplied value should be copied to the address which is include by variable i.


So this is the first chapter is finished here.

Comments

Popular posts from this blog

Privacy Policy