November 24, 2023

basic concept of C Programming

basic concept of C Programming in one post

smartslider3 slider=”2″]

What is Programming?

Computer programming is a medium for us to communicate with computers, just like we use Hindi or English to communicate with each other. Programming is a way for us to deliver our instructions to the computer.

What is C?

C is a programming language. C is one of the oldest and finest programming languages. C was developed by Dennis Ritchie in 1972.

Uses of C

C is a language that is used to program a wide variety of systems. Some of the uses of C are as follows:

  • Major parts of Windows, Linux, and other operating systems are written in C.
  • C is used to write driver programs for devices like Tablets, Printers, etc.
  • C language is used to program embedded systems where programs need to run faster in limited memory.
  • C is used to develop games, an area where latency is very important, i.e., a computer has to react quickly to user input.
The basic structure of a C program

All c programs have to follow a basic structure. A c program starts with the main function and executes instructions presents inside it. Each instruction terminated with a semicolon(;)

There are some basic rules which are applicable to all the c programs:

  • Every program’s execution starts from the main function.
  • All the statements are terminated with a semi-colon.
  • Instructions are case-sensitive.
  • Instructions are executed in the same order in which they are written.

basic concept of C Programming

#include<stdio.h>

int main() {

printf(“Hello,World”);

return 0;

}

 

Source Code

  • Source code is code which is written by The programmer In human readable from with proper programming syntaxes.

Compiler

  • Compiler is a software module which translate (convert) Source code of a into executable code.

Executable

  • Executable code is a machine understandable code. Which can executed by a machine(OS).

Variable

  • Variable is a container that store a data Value.
  • variable is a memory location in the program’s memory which is used to store data value or information. Value store in a variable can be modified during program’s execution.

A variable is a container that stores a ‘value.’ In the kitchen, we have containers storing rice, dal, sugar, etc. Similar to that variable in c stores the value of a constant. Example:

a = 3a is assigned “3”
b = 4.7b is assigned “4.7”
c = ‘A’c is assigned “A”
Rules for naming variables in c:

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

2. No commas or blanks are allowed.

3. No special symbol other than underscore is allowed

4. Variable names are case sensitive

 

Contents

  • Contents are the fixed values that do not changed during the execution of a program.Like integer,float,string etc.

Type of content

Primarily there are 3 types of constant:

1. Integer Constant-1,6,7,9
2. Real Constant-322.1,2.5,7.0
3. Character Constant‘a’,’$’,’@’(must be enclosed within single inverted commas)
Types of variables
Integer variablesint a=3;
Real variablesint a=7.7 (wrong as 7.7 is real) ; float a=7.7;
Character variableschar a=’B’;
Library functions

C language has a lot of valuable library functions which is used to carry out a certain task; for instance, printf function is used to print values on the screen.

printf(“This is %d”,i);

// %d for integers

// %f for real values

// %c for characters
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 a comment.
  2. Multi-line comment : /*This is multi-line comment*/

Comments in a C program are not executed and ignored.

Receiving input from the user

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

The syntax for using scanf:

scanf(“%d”,&i); // [This & is important]

& is the “address of” operator, and it means that the supplied value should be copied to the address which is indicated by variable i.

you need to know operators