Basic questions about C Language

Source: Internet
Author: User

1. If int A = 1, B = 2, c = 3, D = 4; then the conditional expression "A <B? A: C <D? The value of C: D is __?

Resolution: Condition operator? : The combination is from right to left, then the combination of the expression is represented in parentheses: (A <B? A: (C <D? C: d ))
Answer: 1

2. I = 10 is known; the value of the expression "20-0 <= I <= 9" is __?

Analysis: in binary operators, Arithmetic Operators have the highest level, Relational operators followed by logical operators. The concatenation of expressions is represented by parentheses (20-0) <= I <= 9
Answer: 1

3. Int x = 1; U is known. Run the statement "Y = ++ x> 5 & ++ x <10;" and the value of variable X is __?

Resolution: In an expression, the single object operator ++ is the highest, the relational operator level is higher than the logical operator level, and the value assignment operator = is the lowest. The concatenation of expressions is represented by brackets y = (++ X)> 5) & (++ X) <10). For logical operators &&, when the preceding part is false, the latter part is not calculated. Therefore, the result (++ X)> 5) is false, followed by (++ X) <10) so the result of X is 2, and the result of Y is 0.
Answer: 2

4. Int I = 1 is known; execute the statement "while (I ++ <4);" and the variable I value is __?

Resolution: N ++ indicates that the value of Variable N is used first, and then the value of N is increased by 1; + + N indicates that the value of N is increased by 1, and then the value of Variable N is used. For example, if the * PTR ++ and * (PTR ++) results are consistent, they all indicate "First * PTR, then PTR ++ ".
Answer: 5

5. macro definition:
# Define PR (FMT, Val) printf (# Val "= %" # FMT "/T", (VAL ))
# Define NL putchar ('/N ')
# Define print1 (F, X1) Pr (F, X1), NL
So, print1 (d, 5); what are the extended results?

// This call is first extended to RP (d, 5) nL
// Then extend printf (#5 "= %" # D "/T", (5), putchar ('/N ')
// Last extended printf ("5 = % d/T", (5), putchar ('/N '))
From C language confusing

 

6. programming style selection of correct conditions

(1)
Do
{
If (! A) continue;
Else B;
C;
} While ();

// For the first transformation, remove the "redundant" Continue statement first.
Do {
If (a) {B; C ;}
} While ();

// For the second transformation, replace the "Do... while" and if statements with the while statements.
While ()
{
B; C;
}

 

(2)

While (C = getchar ()! = '/N ')
{
If (C = '') continue;
If (C = '/t') continue;
If (C <'0') Return (other );
If (C <= '9') Return (DIGIT );
If (C <'A') Return (other );
If (C <= 'Z') Return (alpha );

Return (other );
}
Return (EoL );

 

After Transformation:

While (C = getchar ()! = '/N ')
{
If (C> = 'A' & C <= 'Z') return Alpha;
Else if (C> = '0' & C <= '9') return digit;
Else if (C! = ''& C <= '/t') return Other;
}
Return (EoL );

From C language confusing

 

7. A question about pointers
Int P;
* P ++ = * (p ++)
* ++ P = * (++ P)
+ + * P = ++ (* P)

 

8.
Int A [3] [3] = {1, 2, 3}, {4, 5, 6}, {7, 8, 9 }};

The values of a and a [0] are the same address, but they are different. Their types are different, which results in the same expression in the arithmetic operation on the address, A + 1 and a [0] + 1 have different meanings. The former points to the next ternary int array, and the latter points to the next int integer pointer.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.