• Chapter2 Introducing C-Review Questions


    1.What are the basic module of a C program called?

    They are called functions.

    2.What is a syntax error? Give an example of one in English and one in C.

    A syntax error is a violation of the rules governing how sentences or programs are put together. Here's an example in English:"Me speak English good." Here's an example in C.

    printf"Where are the parentheses?";

    3.What is a semantic error? Give an example of one in English and one in C.

    A semantic error is one of meaning. Here's an example in English : " This sentence is excellent Czech."  Here's a C example:

    thrice_n = 3 + n;

    4.Indiana Sloth has prepared the following program and brought it to you for approval. Please help him out. 

    Line 1: Begin with a #; spell the file stdio.h; place the filename within angle brackets.

    Line 2: Use() , not {}; end the comment with */, not /*.

    Line 3: Use {, not (.

    Line 4: Complete the statement with a semicolon.

    Line 5: Indiana got this one (the blank line) right!

    Line 6: Use =, not := for assignment.(Apparently, Indiana knows a little Pascal.) User 52, not 56, weeks per year.

    Line 7: Should be

    printf("There are %d weeks in a year.
    ", s);

    Line 8: There isn't a line 9, but there should be, and it should consist of the closing brace, }.

    5.  Assuming that each of the following examples is part of a complete program, what will each one print? 

         a. printf("Baa Baa Black Sheep.");

             printf("Have you any wool? ");  

         b. printf("Begone! O creature of lard! ");  

         c. printf("What? No/nfish? ");  

         d. int num;      

            num = 2;    

            printf("%d + %d = %d", num, num, num + num);     

    a: Baa Baa Black Sheep.Have you any wool? (Note that there's no space after the period. You could have had a space by using " have instead of "have.)

    b: Begone!

        O creature of lard! (Note that the cursor is left at the end of the second line.)

    c: What?

        No/nfish? (Note that the slash[/] does not have the same effect as the backslash []; it simply prints as a slash.)

    6.    Which of the following are C keywords?  main ,  int ,  function ,  char ,  =    

    int and char. 

    7.    How would you print the values of the variables  words  and  lines  so they appear in the following form: 
         

           There were 3020 words and 350 lines.   
     
           Here,  3020  and  350  represent the values of the two variables. 

    printf("There were %d words and %d lines.
    ", words, lines);

    8.    Consider the following program: 

    #include <stdio.h>
    
    int main(void) {
        int a, b;
    
        a = 5;
        b = 2;    /* line 7 */
        b = a;    /* line 8 */
        a = b;    /* line 9 */
        printf("%d %d
    ", b, a);
        return 0;
    }

     What is the program state after line 7? Line 8? Line 9? 

    After line 7, a is 5 and b is 2. After line 8, both a and b are 5. After line 9, both a and b are still 5. (Note that a cant be 2 because by the time you say a = b; b has already been changed to 5.)

     9.    Consider the following program: 

    #include <stdio.h>
    
    int main(void) {
        int x, y;
    
        x = 10;
        y = 5;          /* line 7 */
        y = x + y;      /* line 8 */
        x = x * y;      /* line 9 */
        printf("%d %d
    ", x, y);
        return 0;
    }
    

    What is the program state after line 7? Line 8? Line 9? 

    After line 7, x is 10 and y is 5. After line 8, x is 10 and y is 15. After line 9, x is 150 and y is 15.

    苟利国家生死以, 岂因祸福避趋之
  • 相关阅读:
    C#实现清理系统内存
    WinForm 程序加管理员权限
    DataGridView 绑定List集合后实现自定义排序
    swfupload提示“错误302”的解决方法
    C# WinForm捕获全局异常
    C# WinForm应用程序降低系统内存占用方法
    清除webBrowser 缓存和Cookie的解决方案
    ThInkPHP加密和解密cookie(登录操作)
    prestashop 首页轮播幻灯片图片修改
    网页内容分享到微信
  • 原文地址:https://www.cnblogs.com/chintsai/p/10291573.html
Copyright © 2020-2023  润新知