Write the output of the following C codes, with proper justification for each.
i) main()
{
int a = 2, b = 4, c = 5;
a = b + c;
b = a + c;
c = a - b;
printf("%d,%d,%d", a, b, c);
}
ii) main()
{
printf("%d", ‘C’ + ‘P’ + ‘r’ + ‘o’ + ‘g’ + ‘r’ + ‘a’ + ‘m’);
}
iii) main()
{
int i, j = 1;
for(i = 1; i <= 10; i = i + 2)
{
j = i - j;
while(j <= 2)
printf("%d ", i+j++);
}
}
iv) main()
{
int a = 10, b = 20, c = 30;
int *p = 2;
a = c/*p;
b = c;
printf("a = %d, b = %d", a, b);
}
v) func(int x)
{
static int a = 0;
a += x;
return(a);
}
main()
{
int p;
for(p = 1; p <= 5; ++p)
printf("%d", fun(p));
}
i)
main() {
int a = 2, b = 4, c = 5;
a = b + c; // a = 4 + 5 = 9
b = a + c; // b = 9 + 5 = 14
c = a - b; // c = 9 - 14 = -5
printf("%d,%d,%d", a, b, c); // Output: 9,14,-5
}
Explanation:
- Initially, `a` is assigned 2, `b` is assigned 4, and `c` is assigned 5.
- Then, `a` is updated to the sum of `b` and `c`, `b` is updated to the sum of the updated `a` and `c`, and `c` is updated to the difference between the updated `a` and `b`.
- Finally, the values of `a`, `b`, and `c` are printed.
ii)
main() {
printf("%d", 'C' + 'P' + 'r' + 'o' + 'g' + 'r' + 'a' + 'm');
}
Explanation:
- Characters in C are represented by their ASCII values.
- So, this code computes the sum of the ASCII
_______ ______ ________ ______ _________ ____ ____.
_______ __________ _______ _________ ____ _______.
___ __________ __________ _____ _________ ________ ___ ____ ________.
_______ _______ _____ _____ ______ _____ _____.
___ ____ ______ ___ ________ __________ _______.
___ __________ ___ ___ __________ __________ _________ __________ _________ ______ _______.
__________ ______ ____ _________ ___ ________ _______ ________ ______ ______ _______ _____.
_________ ______ ______ __________ _________ ___ _____ ________.
________ ___ ___ _____ ________ __________.
____ _____ ____ ___ _______ __________ __________ ___ ________ ____.
__________ _____ _________ _________ ______ _____ _________ _____ ___.
____ _________ ___ ____ _________ ______ __________.
_______ _______ _________ _______ _____ ____ ______ ________ __________ ________ __________.
___ ________ ______ _________ ______ _______ _______.
__________ __________ _____ ________ ________ ____ _________ ______ ___.
_____ ________ ______ _________ __________ __________ ____ ____ _______ ______ _________.
__________ ___ _____ _____ ___ ___ _________ ____.
___ ____ _____ _____ ___ ________.
__________ _______ _________ _________ _________ ___ _________ _________ _________.
_______ _________ ____ ________ ____ ___ ________ ___ ____.
_______ ___ _________ ____ ____ ________ _______ _____ _____ ____.
________ ___ ________ _____ _________ ______ __________.
______ ____ ___ _______ __________ ________ _______ _________ ________ _______ __________ ______.
_______ ____ _______ ____ ____ ____ ____ _____ ____ ________ ____ _______.
_______ ________ _______ _____ ___ ______ __________ _______ _______ ______ __________ _______.
_______ __________ ___ ________ ___ __________ _______ _________.
_________ _____ _______ ________ ________ ____.
____ _____ ___ _______ _____ _____ _________ _________ _________ __________ ____ ___.
_______ ________ _________ __________ _____ _________ ________ ____ ______ _________ ____.
_____ _________ _________ ____ _________ ______ _____ ____ ___ _________ _____.
_______ _______ ___ ____ ________ ____ _________.
________ _____ _________ ____ _________ ___ ___ ___.
________ ____ _______ ___ ____.
__________ _________ _____ _____ _______ _______ ______ ____ _________ ________ _______ _____.
______ ____ ____ ________ ______ _____ ___ _________ ___.
_______ _____ ________ _____ ____ ___ ___.
___ ________ ___ ____ _______ _________ _____ ________ _________ _______ _______ ___.
____ _________ _______ _____ ________ __________.
_________ _________ __________ _________ _________ ______ __________ ______.
_____ _______ _______ ____ ______ __________ _________ __________ _______.
______ _____ _____ ____ ______ _________ ________ _______ __________ ______ ____ ____.
___ ________ ___ __________ __________ ________ ________.
__________ __________ _________ _________ ____ ____ ____ ______ ________ ______ _________ _________.
_____ ________ ____ __________ _____ ______ _____ ___ ______ ___ ___.
___ _______ ___ ______ ______.
__________ ___ ____ _______ ________ _________ ________.
____ ___ __________ __________ _____ ______ __________ ______ ___ ________ _____ ________.
___ ______ _______ _________ ____ _______ ______ _______.
_____.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required