C Primer Plus 第二章练习题所学

1:\t的作用是插入对表符,使得文本对齐

eg

#include <stdio.h>

int main() {
    printf("Name\tAge\tLocation\n");
    printf("Alice\t23\tCalifornia\n");
    printf("Bob\t30\tNew York\n");
    return 0;
}

Name    Age     Location
Alice   23      California
Bob     30      New York

 --------------------------------------------------------------------------------------------------------------------------------

2:Q;为什么函数的调用可以在函数定义之前?

A;因为最初的编译器的编译,一个编译单元的时候,是按顺序处理一个一个的函数,它们生成函数的时候不会直接链接,而是根据你的。这个函数声明生成一定就是根据函数声明和调用约定,去生成一定的这个出站或入站的操作。所以说,你必须得告诉编译器函数长什么样,该生成怎样的,出站出来操作,他才能给你编译。至于函数,从定位呀,链接呀,这都是链接器做的事儿,跟编辑没关系。

ps;函数声明不是必要的,没有函数声明也可以是函数调用在函数声明之前

---------------------------------------------------------------------------------------------------------------------------------

最后是八道题的code

/*第一题

#include <stdio.h>

int main() {

    printf("Gustav Mahler\n");

    printf("Gustav \n Mahler\n");

    printf("Gustav");

    printf(" Mahler");

    return 0;

}*/

/*第二题

#include <stdio.h>

int main() {

    printf("please enter your name: ");

    char name[100];

    scanf("%s", name);

    printf("Hello, %s!\n", name);

    printf("please enter you location: ");

    char location[100];

    scanf("%s", location);

    printf(" %s.\n", location);

    return 0;

}*/

/*第三题

#include <stdio.h>

int main() {

    int age;

    printf("please enter your age: \n");

    scanf("%d", &age);

    printf("you have lived for %d days", age * 365);

    return 0;

}*/

/*第四题

#include <stdio.h>

char jolly(void);

char deny(void);

int main() {

    jolly();

    jolly();

    jolly();

    deny();

    return 0;

}

char jolly(void) {

    printf("Jolly good!\n");

    return 0;

}  

char deny(void) {

    printf("I'm sorry, Dave.\n");

    return 0;      

}*/

/*第五题

#include <stdio.h>

int br();

int ic();

int main() {

    br();

    ic();

    printf("\n");

    br();

    printf("\n");

    ic();

    return 0;

}

int br(){

    printf("Brazil,Russia");

    return 0;

}

int ic(){

    printf("India,China");

    return 0;

}*/

/*第六题

#include <stdio.h>

int main() {

    int toss = 10;

    printf("Toss a coin %d times:\n", toss);

    printf("Heads: %d\n", toss*2);

    printf("Tails: %d\n", toss*3);

    return 0;

}*/

/*第七题

#include <stdio.h>

int smile(void);

int main() {

    smile();

    smile();

    smile();

    printf("\n");

    smile();

    smile();

    printf("\n");

    smile();

    return 0;

}

int smile(void) {

    printf("smile!");

    return 0;

}*/

/*第八题

#include <stdio.h>

int one_three();

int two();

int main() {

    printf("staring now\n");

    one_three();

    printf("\n");

    two();

    printf("\n");

    printf("three\n");

    printf("done!\n");

    return 0;

}

int one_three() {

    printf("one");

    return 0;

}

int two() {

    printf("two");

    return 0;

}

*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值