What will be the output of the following program?12345678910#include <stdio.h> int main() { int a[10]; *a = 7; *(a+1) = 12; int p = *(a+1) / *a; printf("%d", p); return 0;}
Question
What will be the output of the following program?12345678910#include <stdio.h> int main() { int a[10]; *a = 7; *(a+1) = 12; int p = *(a+1) / *a; printf("%d", p); return 0;}
Solution
The output of the program will be 1.
Here's the step by step explanation:
- An integer array
aof size 10 is declared. - The first element of the array
a(i.e.,a[0]) is set to 7. - The second element of the array
a(i.e.,a[1]) is set to 12. - An integer
pis declared and set to the result of the division of the second element of the arrayaby the first element of the arraya(i.e.,12 / 7). - Since both numbers are integers, the division operation will also result in an integer. In C, when you divide an integer by another integer, the result is also an integer. This means that any fractional part will be truncated. So,
12 / 7equals1.71428571but since we are dealing with integers, it will be truncated to1. - The value of
p(which is1) is printed. - The program returns 0, indicating successful termination.
Similar Questions
What will be the output of the following program?1234567891011121314151617181920#include <stdio.h>void one();void two();void one() { for(int i = 0; i < 2; i++){ two(); }}void two() { printf("TWO ");}int main(){ one(); two(); return 0;}
What will be the output of the following program?
What will be the output of the following program?12345678910#include <stdio.h> int main() { int a[10]; *a = 7; *(a+1) = 12; int p = *(a+1) / *a; printf("%d", p); return 0;}
What will be the output of the following program?12345678910111213#include <stdio.h> int ren(int n) { if (n == 6) return n; else return 2*ren(n+1);}int main() { printf("%d", ren(2)); return 0;}
What will be the output of the following code?
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.