0% found this document useful (0 votes)
23 views4 pages

Chapter 2 Code

Uploaded by

hetvimagiya485
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Chapter 2 Code

Uploaded by

hetvimagiya485
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

C Language Tutorial

(Basic to Advanced)

Topics to be covered :
Installation + Setup
Chapter 1 - Variables, Data types + Input/Output
Chapter 2 - Instructions & Operators
Chapter 3 - Conditional Statements
Chapter 4 - Loop Control Statements
Chapter 5 - Functions & Recursion
Chapter 6 - Pointers
Chapter 7 - Arrays
Chapter 8 - Strings
Chapter 9 - Structures
Chapter 10 - File I/O
Chapter 11 - Dynamic Memory Allocation

Instructions & Operators


(Chapter 2)

1. Type Declaration Instructions


#include<stdio.h>

int main() {
int age = 22;
int oldAge = age;
int newAge = oldAge + 2;
printf("new age is : %d", newAge);

int rupee = 1, dollar;


dollar = 74;

/*
order of declaration is important - Wrong Declaration Order
float pi = 3.14;
float area = pi * rad * rad;
float rad = 3;
*/
// valid declaration
int age1, age2, age3;
age1 = age2 = age3 = 22;

//invalid
//int a1 = a2 = a3 = 22;

return 0;
}

2. Arithmetic Instructions
#include<stdio.h>

int main() {
int a = 1, b = 2, c = 3;
//valid
a = b + c;

//invalid
// b + c = a;

printf("%d \n", 3 % 2);


printf("%d \n", -3 % 2);
return 0;
}

> Type Conversion


#include<stdio.h>

int main() {
printf("sum of 2 & 3 : %d", 2 + 3);
printf("sum of 2.0 & 3 : %f", 2.0 + 3);
printf("sum of 2.0 & 3.0 : %f", 2.0 + 3.0);
return 0;
}

> Associativity
#include<stdio.h>

int main() {
printf(" Output : %d", 5+2/2*3);
return 0;
}

3. Relational Operator
#include<stdio.h>

int main() {
printf("%d \n", 4==4);

printf("%d \n", 4<3);


printf("%d \n", 3<4);
printf("%d \n", 4<4);
printf("%d \n", 4<=4);

printf("%d \n", 4>3);


printf("%d \n", 3>4);
printf("%d \n", 4>4);
printf("%d \n", 4>=4);

printf("%d \n", 4!=4);


printf("%d \n", 3!=4);
return 0;
}

4. Logical Operator
#include<stdio.h>

int main() {
printf("%d \n", 3<4 && 3<5);
printf("%d \n", 3<4 && 5<4);

printf("%d \n", 3<4 && 5<4);


printf("%d \n", 3>4 && 5>4);
printf("%d \n", 3<4 && 3<5);

printf("%d \n", !(3<4 && 3<5));


printf("%d \n", !(4<3 || 5<3));
return 0;
}
5. Assignment Operator
# include <stdio.h>

int main() {
int a = 10;
a += 10;
printf("a+10 = %d \n", a);
a -= 10;
printf("a-10 = %d \n", a);
a *= 10;
printf("a*10 = %d \n", a);
a /= 10;
printf("a/10 = %d \n", a);
a %= 10;
printf("a%c10 = %d \n", '%', a);
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy