0% found this document useful (0 votes)
5 views5 pages

CSE220 Unit04 Behavior Quiz

The document contains a quiz on C programming behavior, featuring seven questions that test knowledge on topics such as signed and unsigned overflow, float assignment, character and integer conversion, type conversion, and constants. Each question presents a code snippet followed by multiple-choice answers. The quiz aims to assess understanding of potential outcomes and behaviors in C programming scenarios.
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)
5 views5 pages

CSE220 Unit04 Behavior Quiz

The document contains a quiz on C programming behavior, featuring seven questions that test knowledge on topics such as signed and unsigned overflow, float assignment, character and integer conversion, type conversion, and constants. Each question presents a code snippet followed by multiple-choice answers. The quiz aims to assess understanding of potential outcomes and behaviors in C programming scenarios.
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/ 5

CSE220 Unit 04 - C Programming Behavior Quiz

1. Question 1: Signed and Unsigned Overflow

```

#include <stdio.h>

int main() {

unsigned int x = 4294967295;

x = x + 1;

printf("%u\n", x);

return 0;

```

What will this program print?

A) 0

B) 4294967296

C) It causes a runtime error

D) The code does not compile

2. Question 2: Float Assignment

```

#include <stdio.h>

int main() {

float f;

f = 1.0e100;

printf("%f\n", f);
return 0;

```

What happens here?

A) It prints 1.000000

B) It prints a very large float

C) Compiler error: incompatible type

D) Undefined or wrong value due to overflow

3. Question 3: Character and Integer Conversion

```

#include <stdio.h>

int main() {

char c = 65;

c = c + 1;

printf("%c\n", c);

return 0;

```

What is the output?

A) A

B) B

C) 66

D) Compilation error

4. Question 4: Type Conversion on Assignment

```
#include <stdio.h>

int main() {

int i;

i = 1.0e20;

printf("%d\n", i);

return 0;

```

What will happen?

A) It prints 100000000000000000000

B) It prints 0

C) Compiler warning or undefined behavior

D) It prints a truncated float

5. Question 5: Order of Type Casting

```

#include <stdio.h>

int main() {

int j = 1000000;

long i;

i = (long)(j * j);

printf("%ld\n", i);

return 0;

```
Will this print the correct square of 1,000,000?

A) Yes, the cast ensures the result is stored in a long

B) No, overflow happens before the cast

C) It prints an error message

D) The program does not compile

6. Question 6: Type Conversion to Bool

```

#include <stdio.h>

int main() {

int x = -42;

_Bool b = x;

printf("%d\n", b);

return 0;

```

What will this program print?

A) 0

B) 1

C) -42

D) Undefined behavior

7. Question 7: Constants and Type Limits

```

#include <stdio.h>

int main() {
char c = 10000;

float f = 1.0e100;

int i = 1.0e20;

printf("%d %f %d\n", c, f, i);

return 0;

```

What happens here?

A) It compiles and prints garbage values

B) It fails to compile due to invalid assignments

C) Only `f` is correctly initialized

D) Only `i` causes an error

You might also like