Write the output of the following C codes, with proper justification for each.
i) main()
{
int i = 5, j = 6, k = 7;
printf("%d", i++ - ++j + ++k);
}
ii) main()
{
char day[10] = "SUNDAY";
day[0] = 77;
day[1] = 79;
printf("%s", day);
}
iii) main()
{
int i = 3;
while(i--)
{
int i = 1;
printf("%d ", i);
i++;
}
}
iv) int f(int n)
{
if(n < 1)
return n;
else
return n*n + f(n-1);
}
main()
{
printf("%d", f(5));
}
v) struct employee
{
char name[20];
int id;
long salary;
}emp = {"Piyush", 1, 50000};
main()
{
printf("Name = %s ", emp.name);
printf("ID =%d", emp.id);
printf("Salary = %d", emp.salary);
}
i) The output of this C code will be -8. The expression i++ - ++j + ++k is evaluated from left to right. First, i++ returns the current value of i (which is 5) and then increments i. Next, ++j increments j and returns the new value (which is 7). Finally, ++k increments k and returns the new value (which is 8). Substituting these values into the expression, we get 5 - 7 + 8, which is equal to -8.
ii) The output of this C code will be "MONDAY". The array day is initially set to "SUNDAY". The statements day[0] = 77; and day[1] = 79; change the first two characters of the array to 'M' and 'O', respectively.
___ ______ ___ ___ _________ ______ _____ _______ __________ ______ __________ ___.
________ _________ ________ ______ ______ ___ ________ _____ _______ _______ _______ _______.
__________ ____ ____ _______ _______ ________ __________ _____.
_______ ___ _____ ________ __________ ________ ____ ________.
_________ _________ __________ ______ ______ _________ ________ _______.
__________ __________ ________ ______ _________ _________ _____ ____ _______ __________ ___ _________.
_______ ______ ______ ________ _________ ________ _____ _______ ____ __________ _____.
___ ___ __________ _____ _____.
_________ ______ ________ _______ _________ __________ _________ _______ _____.
___ ___ ____ ______ ____ ________ _________ ___ _____ __________.
_______ _____ _________ ___ ____ ____ ____ ___ ______ ________ _______ ____.
_________ _________ ___ ______ ______ ______ ____ _______.
____ _________ _______ _________ ____ _____ _______ _____ ____ _________ ______ _______.
_________ ______ ________ ______ __________.
___ _____ _____ ___ _________ _____ ___ ___ _____ ____.
___ _________ _____ ___ ______ _______ ________ ______ ___ ___ _____.
_____ __________ ______ _______ ______ _____ _____ ________ __________.
__________ ____ _______ ____ __________.
_____ ____ _______ _________ _______ ______ _________ ________.
__________ _________ ____ ________ _______ ___ _____ ______ _____ ______ ________.
__________ ____ ____ ____ _________ ________ _______.
___ ________ _________ _________ ________.
______ _______ ___ ________ _____ ___ ______.
_____ __________ _____ _____ ________ _________ ______ ____ ____ ________ ______.
________ _______ ___ _____ ___ _________ ___ _________ __________ _____ ______.
______ __________ ______ ___ _____ ________ _________ _____.
________ _________ ____ ________ _______ ___ ______ _____ ____ ___.
_____ ____ __________ ________ _________ ____ _____ ________ ________ ___ _________.
____ _____ _____ ______ ___.
___ ________ ____ _____ _______ ____ __________ ________ ___ _________ ____.
______ ____ ________ ___ _____ ______ ____ ____.
___ ____ ____ __________ _______ ________ ___ __________ __________ _______ ______.
__________ ____ ___ __________ ______ ____ ____.
_____ _______ _________ _________ ____ _______ ______ __________.
______ ___ ______ ________ ______ _________ _______ ________ ___ _______.
_____ ________ __________.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required