C Programming
C Programming

C notes from scratch to advance | Instructions and operators in C | #C

C notes from scratch to advance | Instructions and operators in C | #C

C Programming
C Programming

C is a programming language as we have discussed earlier about languages and Programming Languages. C is one of the oldest and finest programming languages.

In previous, we have discussed about C basics , what is C , What is Programming , What is computer language , uses and all in chapter 0. And in chapter 1 we have discussed variables, nomenclature , constants , types , keywords , basic structure of C program and we have made our first program also.

Links of previous notes : 

Chapter 0 (basics) : click here

Chapter 1 (Variable,Constant and Keywords) :  click here 

C programming
C programming

A C program is a set of instructions. Just like a recipe – which contains instructions to prepare a particular dish.

Types of instructions:

1.Type declaration instruction

2. Arithmetic instruction

3.Control instruction

Type of declaration instruction : 

int a;
float b;

other variations:

int i = 10; int j = i, int a = 2;
int j1 = a + j – i;

float b = a+3; float a = 1.1; ==>Error! As we are trying to use a before defining it.

int a,b,c,d;

a=b=c=d=30; ==> Value of a,b,c & d will be 30 each.

Arithmetic Instructions : 

image
Arithmetic Instructions 

Note:

1.No operator is assumed to be present

int i=ab  ( Invalid )

int i=a*b  ( valid )

2.There is no operator to perform exponentiation in c however we can use pow( x , y ) from <math.h>(More later).

Type conversion :  

An Arithmetic operation between

int and int ==> int
int and float ==> float
float and float ==> float

5/2 –> 2 5.0/2 –> 2.5 //IMPORTANT!!
2/5 –> 0 2.0/5 –> 0.4 //IMPORTANT!!

NOTE:

int a = 3.5; //In this case, 3.5 (float) will be denoted to a 3 (int) because a cannot store floats.

float a = 8; // a will store 8.0 [8–>8.0(Promotion to float)]

Quick Quiz:

Question

int k=3.0/9 value of k? and why?

Solution-

3.0/9=0.333, but since k is an int, it cannot store floats & value 0.33 is demoted to 0.

Operator Precedence in C

3*x-8y  is (3x)-(8y) or  3(x-8y)?

In the c language, simple mathematical rules like BODMAS no longer apply.

The answer to the above question is provided by operator precedence & associativity.

Operator precedence

The following table list the operator priority in C

 

Priority Operators
1st * / %
2nd +   –
3rd =

Operators of higher priority are evaluated first in the absence of parenthesis.

Operator associativity 

When operators of equal priority are present in an expression, the tie is taken care of by associativity

x * y / z => (x * y) / z
x / y * z => (x / y) * z

*, / follows left to right associativity.

Control instructions 

Determines the flow of control in a program.

Four types of control instruction in C are:

1. Sequence Control Instruction

2. Decision Control Instruction

3. Loop Control Instruction

4. Case-Control Instruction


Thanks for reading this blog. Hope you get satisfied with the blog and definitely this blog must have valued your time and effort of reading.

Take a time to connect our other digital creations such as Instagram , Facebook and Youtube.

 

🧑‍💻🧑‍💻 Social Media Links of Tech DCode :
👉🏻 YouTube : https://www.youtube.com/channel/UCjJnEdeugftBwQ3yMuD4B_A
👉🏻 Instagram : https://www.instagram.com/thetechdcode/
👉🏻 Facebook Page : https://www.facebook.com/thetechdcode
👉🏻 Twitter : https://twitter.com/thetechdcode
👉🏻 Telegram Channel : https://t.me/thetechdcode
👉🏻 Tech DCode Linktree : https://linktr.ee/thetechdcode
👉🏻 My Personal Handles : https://linktr.ee/virtualshivamin

🧑‍💻🧑‍💻 Social Media Links of SHIVAM SINGH (OWNER) :
👉🏻 Instagram : https://www.instagram.com/virtualshivamin/
👉🏻 Facebook Page : https://www.facebook.com/virtualshivamin/
👉🏻 Twitter : https://twitter.com/virtualshivamin/
👉🏻 Personal Linktree : https://linktr.ee/virtualshivamin 

Leave a Reply

Your email address will not be published. Required fields are marked *