0% found this document useful (0 votes)
12 views

Embedded C Class Assignment 1 - 22BLC1339

This document is a class assignment for the course BECE320E - Embedded C Programming, submitted by a student named Shweta S. It includes various C programming exercises, their outputs, debugging tasks, and explanations regarding code behavior and errors. The assignment covers topics such as bitwise operations, loop constructs, and error handling in C programming.

Uploaded by

janardhanan1711
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)
12 views

Embedded C Class Assignment 1 - 22BLC1339

This document is a class assignment for the course BECE320E - Embedded C Programming, submitted by a student named Shweta S. It includes various C programming exercises, their outputs, debugging tasks, and explanations regarding code behavior and errors. The assignment covers topics such as bitwise operations, loop constructs, and error handling in C programming.

Uploaded by

janardhanan1711
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/ 12

School of Electronics Engineering (SENSE)

B. Tech – Electronics & Computer


Engineering

BECE320E – Embedded C Programming

Submitted By
22BLC1339 - Shweta S

Submitted To
Dr. Balakrishnan R
DATE: 23/01/2024

22BLC1339 1 BECE320E – Embedded C Programming


CLASS ASSIGNMENT - 1
1.​ Find the output of the below C programs:

Code 1:
Answer: z = 6​

22BLC1339 2 BECE320E – Embedded C Programming


Code 2:​
Answer:
4​
4

2.​ How many times will "C" be printed by this code?

Answer:
The letter "C" is printed once for each of the four iterations where the condition is true.
∴ C is printed 4 times

22BLC1339 3 BECE320E – Embedded C Programming


3.​

Answer:​

Code:
C/C++
#include <stdio.h>
int main() {
printf("22BLC1339\n");
int number = 5;
while (number <= 20) {
printf("%d\n", number);
number++;
}
return 0;
}

22BLC1339 4 BECE320E – Embedded C Programming


4.​ ​
Answer:(a)

(b)

●​ For (a): The printf function will print the result of the comparison, 8< 10, which is
1(True).
●​ For (b): Undefined Error: Floating point exception. Error is due to the division by zero.
Error messages vary for compiler.

5.​
Answer:

22BLC1339 5 BECE320E – Embedded C Programming


22BLC1339 6 BECE320E – Embedded C Programming
6.​

Answer:

7.​ Output of the following:

22BLC1339 7 BECE320E Embedded C Programming


Answer:​
Step 1:
●​ Calculation:
●​ c = (a & b) && ((b >> 2) | (a << 1))
●​ Given a = 5 (binary 0101) and b = 12 (binary 1100): Bitwise AND
●​ Final Calculation for Step 1:
●​ c = (4) && (11) evaluates to 1 (true).
●​ Output: c = 1
Step 2:
●​ Condition Check:
●​ Evaluate (a ^ b) || (c & ~b):Bitwise XOR
Since the condition is true, we enter this branch:
●​ Calculation:
●​ c = (a | b) && !(b & a) Bitwise OR
●​ Final Calculation for Step 2:
●​ Therefore, c = (true) && (false) results in c = 0.
●​ Output: c = 0
Step 3:
●​ Calculation:
●​ Perform the final operation: c = (c << 1) | (c >> 1)
●​ Since c is now 0:Left Shift. Thus, the final value of c remains: c = (0) | (0) = 0
●​ Output: Final c = 0

Final Output:
22BLC1339
Step 1: c = 1
Step 2: c = 0
Final c = 0
8.​ Debug the below code.
Code:
C/C++
#include <stdio.h> int main() {
int x = 5;
while (x = 5)
printf("In the loop\n");
x--;
}
return 0;
}

22BLC1339 8 BECE320E – Embedded C Programming


Debugged Code:
C/C++
#include <stdio.h>
int main() {
int x = 5;
while (x > 0) {
printf("In the loop\n");
x--;
}
return 0;
}

Answer:
In the original code, the code will lead to an infinite loop, causing a run-time error. That’s why, I
changed it to x>0, causing getting an output for 5 times.

9.​
Answer: No this will not compile due to a few errors.(Image 1),The corrected code is in Image 2.

22BLC1339 9 BECE320E – Embedded C Programming


10.​
Answer:
The LL suffix tells the compiler to treat this number as a long long int, which avoids any
potential warnings about integer overflow or type mismatches.

11.​

22BLC1339 10
Programming BECE320E – Embedded C
Answer:
The error message: Incrementing a Macro: You cannot increment a macro as if it were a variable.

Answer: Corrected

12.​

Answer:

22BLC1339 11
Programming BECE320E – Embedded C
22BLC1339 12
Programming BECE320E – Embedded C

You might also like