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(...
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
Please answer the above queston (in terms of C programming) and explain answer Semester 2 & Trimester 3B, 2015 COMP1004 Engineering Programming Question 3 - Repetition (20 marks) Q3(a) What will be printed when the following code is executed? (5 marks] #include <stdio.h> int main() int i, j; for(i=1;i<17;i=i+2) { printf("%d==", i); for(j=i; j>0;j--) printf("#"); printf("\n"); return 0; == # 3 = = # # # 5 == ### ## 7 #### #
Can you explane this quastion step by step 29) What is the output of the following program? main () { int i,j,sum= 0, time 01 ; for (i-1;i<6; i++) { j-0; time*=i; while (j<i)(sum+=j;j++;) sumt=time;} printf ("%d 8d", sum, time); Je a) 20 173 b) 120 173 c) 173 20 d) 20 120 e) 173 120
What is the output of the following program? Show each step to get to the output #include <stdio.h> int f(int* a, int* b); int main() { int a = 6, b = 7, c = 8; b = f(&c, &a); printf("a = %d, b = %d, c = %d\n", a, b, c); return 0; } int f(int* a, int* b) { *a = *a + *b; *b = *a - *b; printf("a = %d,...