代码语言:c复制
int score1 = 72;
int score2 = 73;
int score3 = 33;
printf("Average: %fn", (score1 score2 score3) / 3.0);
代码语言:c复制 string words[2];
words[0] = "HI!";
words[1] = "BYE!";
command-line arguments
代码语言:c复制#include <stdio.h>
int main(int argc, string argv[])
{
...
}
argc: argument数量
argv: argument vector
输入的指令转换为:vector(向量), 数量。
代码语言:c复制#include <cs50.h>
#include <stdio.h>
int main(int argc, string argv[])
{
printf("hello, %sn", argv[1]);
}
代码语言:c复制#include <cs50.h>
#include <stdio.h>
int main(int argc, string argv[])
{
printf("hello, %sn", argv[0]);
}
代码语言:c复制#include <cs50.h>
#include <stdio.h>
int main(int argc, string argv[])
{
printf("hello, %sn", argv[2]);
}
代码语言:c复制#include <cs50.h>
#include <stdio.h>
int main(int argc, string argv[])
{
if (argc == 2)
{
printf("hello, %sn", argv[1]);
}
else
{
printf("hello, worldn");
}
}
代码语言:c复制#include <cs50.h>
#include <stdio.h>
int main(int argc, string argv[])
{
for (int i = 0; i < argc; i )
{
printf("%sn", argv[i]);
}
}