Time to put on your thinking hats
This presentation is the property of its rightful owner.
Sponsored Links
1 / 36

Time to Put on your thinking Hats PowerPoint PPT Presentation


  • 34 Views
  • Uploaded on
  • Presentation posted in: General

Time to Put on your thinking Hats. What would be the output. void main() { int a=32767; printf(“%d”, a); }. 32767. What would be the output. void main() { int a=32769; printf(“%d”, a); }. -32767. What would be the output. void main() { int a=1232.5; printf(“%d”, a); }.

Download Presentation

Time to Put on your thinking Hats

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Time to put on your thinking hats

Time toPut on your thinking Hats


What would be the output

What would be the output

void main()

{

int a=32767;

printf(“%d”, a);

}

32767


What would be the output1

What would be the output

void main()

{

int a=32769;

printf(“%d”, a);

}

-32767


What would be the output2

What would be the output

void main()

{

int a=1232.5;

printf(“%d”, a);

}

1233

1232


What would be the output3

What would be the output

void main()

{

int a=-32779.205;

printf(“%d”, a);

}

32757

Subtract 11-1=10 to 32767


What would be the output4

What would be the output

void main()

{

float a=-3279.205;

printf(“%d”, a);

}

-3279


What would be the output5

What would be the output

void main()

{

int a=-3279.205;

printf(“%f”, a);

}

-3279.000000


What would be the output6

What would be the output

void main()

{

float a=-32779.205;

printf(“%f”, a);

}

-32779.205000


What would be the output7

What would be the output

void main()

{

float a=-32779.205;

printf(“%.1f”, a);

}

-32779.2


What would be the output8

What would be the output

void main()

{

float a=69;

printf(“%f”, a);

}

69.000000


What would be the output and how many bytes will it occupy

What would be the output and how many bytes will it occupy

void main()

{

int a,b,c;

a=5;

b=2;

c=a/b;

printf(“%d”, c);

}

2 & 6 bytes

Size of int*3


What would be the output and how many bytes will it occupy1

What would be the output and how many bytes will it occupy

void main()

{

inta,b;

float c;

a=5;

b=2;

c=a/b;

printf(“%f”, c);

}

2.000000

& 8 bytes

Size of int*2 +Size of float


What would be the output and how many bytes will it occupy2

What would be the output and how many bytes will it occupy

void main()

{

float a,b,c;

a=5;

b=2;

c=a/b;

printf(“%f”, c);

}

2.500000

& 12 bytes

Size of float*3


What would be the output and how many bytes will it occupy3

What would be the output and how many bytes will it occupy

void main()

{

inta,b;

float c;

a=5;

b=2;

c=(float)a/b;

printf(“%f”, c);

}

2.500000

&8 bytes

Size of int*2 +Size of float


Time to put on your thinking hats

  • A-Z65-90

  • a-z97-122

  • 0-948-57

  • Special symbols:

    • 0-47

    • 58-64

    • 91-96

    • 123-254


What would be the output9

What would be the output

void main()

{

char s=65;

char ch=‘A’;

char st=‘25’;

printf(“%d”,ch);

printf(“%c”,ch);

printf(“%d”,s);

printf(“%c”,s);

printf(“%c”,st);

printf(“%d”,st);

}

65

A

65

A

2

50


Time to put on your thinking hats

£

  • Try some of these:

    printf(“%c”,-100);

    printf(“%c”,-128);

    printf(“%c”,-130);

    printf(“%c”,100);

    printf(“%d”,-10);

    printf(“%x”,1>>4);

    printf(“%x”,16);

Ç

~

d

-10

ffff

10


Time to put on your thinking hats

  • Try some of these:

    printf(“%d”,-100);

    printf(“%.2f”,128);

    printf(“%f”,-130);

    printf(“%c”,91);

    printf(“%d”,34342);

    printf(“%x”,1004);

    printf(“%x”,16);


Associativity and precedence

Associativity and precedence

9

#include<stdio.h>

void main()

{

printf("%d",5+3*6/2-5);

}

5+18/2-5 // division has higher precedence then + and -

5+9-5 //+ , - has same precedence so check associativity ie. L to r

9


Write a program to swap 2 numbers

Write a program to swap 2 numbers

void main()

{

inta,b,c;

a=5;

b=2;

c=a;

a=b;

b=c;

printf(“%d,%d”,a,b);

}


Time to put on your thinking hats

  • Suppose we print c over here what would be its value?

  • 5, as it copy paste the value and does not cut paste the values


Write a program to swap 2 numbers without using a third variable

Write a program to swap 2 numbers without using a third variable

void main()

{

inta,b;

a=5;

b=2;

a=a+b;

b=a-b;

a=a-b;

printf(“%d,%d”,a,b);

}


Similarly can we write a program to swap 2 numbers using multiplication and division

Similarly , can we Write a program to swap 2 numbers, using multiplication and division

void main()

{

inta,b;

a=5;

b=2;

a=a*b;

?=a/b;

?=a/b;

printf(\n“%d,%d”,a,b);

}


Similarly can we write a program to swap 2 numbers using xor

Similarly , can we Write a program to swap 2 numbers, using XOR(^)

void main()

{

inta,b;

a=5;

b=2;

a=a^b;

b=a^b;

a=a^b;

printf(“\n%d,%d”,a,b);

}


Logic behind xor

Logic behind XOR

  • a=5101

  • b=6110

  • a^b=3011

  • a=3011

  • b=6110

  • a^b=5101

  • a=3011

  • b=5101

  • a^b=6110


Similarly can we write a program to swap 2 numbers in one line

Similarly , can we Write a program to swap 2 numbers in one line

b = (a*a)/a + (a=b) - a;

a^=b^=a^=b;


Till now any problem

Till now any problem?


Time to put on your thinking hats

++ is increment by 1a++ is post increment++a is pre incrementa=a+1;-- is decrement by 1a-- is post decrement--a is pre decrementa=a-1;


What would be the output10

What would be the output

void main()

{

char s=5;

s++;

printf(“%d”,s);

printf(“%d”,s++);

printf(“%d”,s);

printf(“%d”,++s);

printf(“%d”,s);

}

6

6

7

8

8


What would be the output11

What would be the output

void main()

{

int s=5;

s++;

printf(“%d”,s);

printf(“%d”,s--);

printf(“%d”,s);

printf(“%d”,--s);

printf(“%d”,s);

}

6

6

5

4

4


What would be the output12

What would be the output

void main()

{

char s=5;

printf(“%d”,s+++s);

}

What would the compiler read it as?

a++ +a

Ora+ ++a

5+6= 11

Note: Post increment has higher precedence than pre increment


Please try some of these

Please try Some of these

  • printf(“%d”, s++s);

  • printf(“%d”, s++++s);

  • printf(“%d”, s+++++s);

  • printf(“%d”, s++ + ++s);

  • printf(“%d”,++s+++s);

  • printf(“%d”,++s+++s++);

  • printf(“%d”, s+s++);

  • printf(“%d”, s+s++++);


What would be the output13

What would be the output

void main()

{

char s=5;

printf(“%d%d%d%d”,++s,++s,s++,++s);

printf(“\n%d”,s);

}

9 8 6 6

9

Note: Post increment has higher precedence than pre increment,

but here associativety is Right to Left


Time to put on your thinking hats

The distance between 2 cities (in km) is input through the keyboard. Write a program to convert and print the distance in meters, feet, inches and centimeters.

  • 1 km=1000m

  • 1m=100cm

  • I inch=2.54 cm

  • 1 feet=12inch


What would be the output14

What would be the output

Bitwise Operators

3^2&~1

11 ^ 10 & ~ 01

11 ^ 10 & 10

11 ^ 10

01

1


Time to put on your thinking hats

Best of Luck


  • Login