8escs01 problem solving through programming unit-2: c programming basics



Download 0,98 Mb.
bet13/22
Sana19.05.2023
Hajmi0,98 Mb.
#940862
1   ...   9   10   11   12   13   14   15   16   ...   22
Bog'liq
Module 2 c program

(F) CONDITIONAL OPERATORS
  • Conditional operators return one value if condition is true and returns another value is condition is false.
  • This operator is also called as ternary operator.
  • Syntax: (Condition? true_value: false_value);
  • Example: (A > 100 ? 0 : 1);

  • Note: In above example, if A is greater than 100, 0 is returned else 1 is returned. This is equal to if else conditional statements.

OPERATORS AND EXPRESSIONS


void main()
{
int x=1, y ;
y = ( x ==1 ? 2 : 0 ) ;
printf(“x value is %d\n”, x); printf(“y value is %d”, y);
}
(F) CONDITIONAL OPERATORS - EXAMPLE
#include
Output:
x value is 1 y value is 2

OPERATORS AND EXPRESSIONS

  • Example: Assume if A = 60; and B = 13;

  • A = 0011 1100 B = 0000 1101
    A&B = 0000 1100
    A|B = 0011 1101
    A^B = 0011 0001
    ~A = 1100 0011

57
(G) BITWISE OPERATORS
  • Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ are as follows:

OPERATORS AND EXPRESSIONS


(G) BITWISE OPERATORS
  • The Bitwise operators supported by C language are listed in the following table.

OPERATORS AND EXPRESSIONS


(G) BITWISE OPERATORS - EXAMPLE
#include
void main( )

{ int a = 60;

/* 60 = 0011 1100 */

int b = 13;
int c = 0; c = a & b;

/* 13 = 0000 1101 */
/* 12 = 0000 1100 */

printf("Line 1 - Value of c is %d\n", c );

c = a | b;

/* 61 = 0011 1101 */

printf("Line 2 - Value of c is %d\n", c );

c = a ^ b;

/* 49 = 0011 0001 */

printf("Line 3 - Value of c is %d\n", c );

c = ~a;

/*-61 = 1100 0011 */

printf("Line 4 - Value of c is %d\n", c );

c = a << 2;

/* 240 = 1111 0000 */

printf("Line 5 - Value of c is %d\n", c );
printf("Line 6 - Value of c is %d\n", c );
}

c = a >> 2;

/* 15 = 0000 1111 */

Download 0,98 Mb.

Do'stlaringiz bilan baham:
1   ...   9   10   11   12   13   14   15   16   ...   22




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish