QUESTION: Explain the output of following C code by showing dry run for each step.
main( )
{
int a[5] = { 5, 1, 15, 20, 25 } ;
int i, j, k = 1, m ;
i = ++a[1] ;
j = a[1]++ ;
m = a[i++] ;
printf ( "\n%d %d %d", i, j, m ) ;
}
Hopefully all yours doubt will clear if you have left with any doubt please let me know in comment. I will try my best to resolve that.
Each statement is explained in comments
#include<stdio.h>
#include<stdlib.h>
main( )
{
// array declaration where index starts from 0 to 4
// a[0]=5, a[1]=1, a[2]=15, a[3]=20, a[4]=25
int a[5] = { 5, 1, 15, 20, 25 } ;
// declaration of variables
int i, j, k = 1, m ;
// here a[1] is pre-increment so first a[1] is incremented and then
stored in i
// so a[1] is 2 and i = 2
i = ++a[1] ;
// here a[1] post-increment so first value is stored in j then
increment in value of a[1]
// so a[1] =2 before increment so value of j is stored first i.e. 2
then increment in a[1] so a[1] = 3 now
j = a[1]++ ;
// here i is post-incremented first this statement is incremented
then value so i is incremented
// so i before statement is 2 and a[2] is 15 so m = 15 and i after
statement is incremented so i =3 now
m = a[i++] ;
// i = 3 and j=2 and m = 15 will be printed
printf ( "\n%d %d %d", i, j, m ) ;
return 0;
}
Screenshot of output :-

QUESTION: Explain the output of following C code by showing dry run for each step. main(...
QUESTION 9 What will be the output of following code snippet? int a[3] = {1, 2, 3}; int *p = a; int **r = &p; printf("%p %p", *r, a); A. Different memory addresses printed B. 1 2 C. Same memory address printed twice D. 1 1 2 points QUESTION 10 What will be the output of following code snippet? int arr[4] = {1, 2, 3, 4}; int *p; p = arr + 3; *p = 5; printf("%d\n", arr[3]); A....
QUESTION 6 What is the output of following C code? struct numbers { int x = 2; int y = 3; } int main() { struct numbers nums; nums.x = 110; nums.y = 100; printf("%d\n%d", nums.x, nums.y); return 0; } A. Compile-time Error B. 110 100 C. 2 3 D. Run-time Error 2 points QUESTION 7 What is the output of following C code? typedef struct student { char *stud; }s1; int main() { s1 s; s.stud...
1.)What would be the output of the following programs: (a) main( ) { int i = 5, j = 2 ; junk ( i, j ) ; printf ( "\n%d %d", i, j ) ; } junk ( int i, int j ) { i = i * i ; j = j * j ; } (b) main( ) { int i = 5, j = 2 ; junk ( &i, &j ) ; printf ( "\n%d %d", i,...
OPERATING SYSTWM
Question 31 What is the output of this C program? #include #include void main() int mptr, *cptr mptr = (int*)malloc(sizeof(int)); printf("%d", "mptr); cptr = (int)calloc(sizeof(int),1); printf("%d","cptr); garbage 0 000 O garbage segmentation fault Question 8 1 pts If this program "Hello" is run from the command line as "Hello 12 3" what is the output? (char '1'is ascii value 49. char '2' is ascii value 50 char'3' is ascii value 51): #include<stdio.h> int main (int argc, char*argv[]) int...
Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */ struct myWord{ char Word[21]; int Length; }; int tokenizeLine(char line[], struct myWord wordList[]); void printList(struct myWord wordList[], int size); void sortList(struct myWord wordList[], int size); /** * main function */ int main() { struct myWord wordList[20]; char line[100]; printf("Enter an English Sentence:\n"); gets(line); int size = tokenizeLine(line, wordList); printf("\n"); printf("Unsorted word list.\n"); printList(wordList, size);...
What is the output of the following code segment? for (k =4; k > 0; k=k - 1){ for (i = 1; i= 5 - k; i=i+1) printf("-"); for (j = 1; j <=2Ak - 1; j=j+1) printf("A"); printf("\n");} Define a struct called Vehicle (be sure to rename it) that contains a make field of length 20, a model field of length 25, and a year:
Given the following code in C, what is the output of this program? (10 Points) int mainO f 5. int i=10; for(int j-l;j-3;j++) int i=5 printf("i=%dn', i); printf("f%d\n", i); return 0;
20) What is the output of the following segment of C code: int avg(int n, int* a); int main () { int array[4]={1,0,6,9}; printf("%d", avg(4, array)+ 1); system("pause"); return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...
24. What will be the output of the following code #include<stdio.h> int main() { char *p; p="%d\n"; p++; p++; printf(p-2, 100); return 0; } a. 100 b. 00 c. 10 d. compiler error e. none of the above 26. What will be the output of the following code #define TRIPPLE(x) (3*x) int x = 4; printf(“triple(%d) = %d \n”,x+1, TRIPPLE(x+1)); a. triple(5) = 12 b. triple(5) = 13 c. triple(4) = 14 d. triple(4) = 15 e. none of the...
please explain very well.Thanks
Question 3) What is the output of the following code? (4 marks) #include <stdio.h> int main(void) Output: int i; for (i = 0;i<4; i++) static int a = 0; int b = 0; a++; b++; printf("%d %d", a,b); 11213141