How many tokens exist in the following statement? Classify each of them. [4 poin
ID: 3726181 • Letter: H
Question
How many tokens exist in the following statement? Classify each of them. [4 points) answer (3*q-P p)/3; 3. Hint: Tokens include identifiers, keywords, operators, punctuations, constants, and string litera printf("Height: %d n", height); Write calls of printf that display a float variable x 4. Identiy the identifers, string literals, and punctuation in the following statement: [3 points) 5. in the following formats: [4 points] a. Exponential notation: right-justified in a field of size 10; six digits after the decimal point. b. Fixed decimal notation: left-justified in a field of size 8; three digits after the decimal point. 6. Suppose we call scanf as follows: [2 points scanf("%f%d%f", &x;, &i;, &y;); If the user enters 12.3 45.6 789 what are the values of x, i, and y after the call? (Assume that x and y are float variables, i is an int va 7. Show the output produced by the following program fragment. Assume that i, j, k are int variables.[18 printf("%d t %d in',, i, j); jshj-2; k = 3; printf("%d %d lt %d In", i, j, k); printf("%d lt %d In", i, j); 1-2;j = 1; printf("%d in', lli + !): printf("%d in', tti 11 tti && ++k);
Explanation / Answer
3. There are 14 tokens in the expression. They are classified as follows:
indentifiers : answer,q,p,p
operators: = , *, -, *, /
constants: 3, 3
separator: ( , )
punctuation: ;
4. The identifications are as follws:
identifiers(name of variabled): height
string literal(set of characters within double quotes) :Height: %d
punctuation: ", ", ;
separators: (,)
5. a. printf("%10.6e",x);
b. printf("%-8.3f",x);
6. x=12.3, i=45, y=789.0
7. output is as follows:
63 8
2 -1 3
3 4
1
1
explanation:
i=7;j=8;
i*=j+1;
thus i=i*(j+1) = 7*9=63. and j=8; since *= has lesser precedence than +.
i=1;j=2;k=3;
i-=j-=k;
-= operator has associativity from right to left.So it is evaluated right to left.
Thus k=3, then j=j-k = 2-3 = -1 andfinally i=i-j=1-(-1)=2
i=5;
j=(i-=2)+1
i-=2 is evaluated first. Now, i=5-2 = 3 and j=3+1 = 4
i=2;j=1;
!i = 0 since i has nonzero value.And !!i=!0 = 1
!j=0 since j also has non zero value
!!i+!j = 1
i=1;j=1;k=1;
++i||++j&&++k = 2 || 2 && 2 = 1 && 2 (since 2||2 = 1)
= 1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.