Error[8]: Undefined offset: 28, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

课程重点速记

  1. C is a low-level language. low-level is also known as machine
    level language.
  2. gdb on MAC M1 gdb is not support, but you can use lldb.
  3. strings stored as character array
  4. null-terminated (last character in array is ‘\0’ null) not writen explicitly in string
    literals

Problem 1.1
a. What do curly braces denote in C? Why does it make sense to use curly braces to surround the body of a function?

b. Describe the difference between the literal values 7, “7”, and ’7’.

c. Consider the statement
double ans = 10.0+2.0/3.0−2.0∗2.0;
Rewrite this statement, inserting parentheses to ensure that ans = 11.0 upon evaluation of
this statement.

Problem 1.2
Consider the statement
double ans = 18.0/squared(2+1);
For each of the four versions of the function macro squared() below, write the corresponding value of ans.

  1. #define squared(x) (x*x)
  2. #define squared(x) (x)*(x)
  3. #define squared(x) ((x)*(x))
  4. return 0;

Problem 1.3
Write the “Hello, 6.087 students” program described in lecture in your favorite text editor and compile and execute it. Turn in a printout or screen shot showing
• the command used to compile your program
• the command used to execute your program (using gdb) • the output of your program

~/D/C/M/lecture1 [2]> lldb p1-3.o
(lldb) target create "p1-3.o"
Current executable set to '/Users/dudu/Documents/C_Programming/MIT_6087/lecture1/p1-3.o' (arm64).
(lldb) r
Process 869 launched: '/Users/dudu/Documents/C_Programming/MIT_6087/lecture1/p1-3.o' (arm64)
Hello, 6.087 studentsProcess 869 exited with status = 0 (0x00000000) 

Problem 1.4
The following lines of code, when arranged in the proper sequence, output the simple message “All your base are belong to us.”

  1. const char msg[] = MSG1;
  2. }
  3. #define MSG1 “All your base are belong to us!”
  4. 6
  5. int main(void) {
  6. #include
  7. puts(msg);
    Write out the proper arrangement (line numbers are sufficient) of this code.
-4-5-2-7-1-3[+++]

Problem 1.5
For each of the following statements, explain why it is not correct, and fix it.
(a) #include ;
(b) int function(void arg1) {
return arg1-1;
}
© #define MESSAGE = “Happy new year!” puts(MESSAGE);

-a no ‘;’

-b the return type of function shall be int but not viod

-c no ‘=’

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Lecture 1 - Introduction. Writing, compiling, and debugging C programs. Hello world._C_内存溢出

Lecture 1 - Introduction. Writing, compiling, and debugging C programs. Hello world.

Lecture 1 - Introduction. Writing, compiling, and debugging C programs. Hello world.,第1张

课程重点速记

  1. C is a low-level language. low-level is also known as machine
    level language.
  2. gdb on MAC M1 gdb is not support, but you can use lldb.
  3. strings stored as character array
  4. null-terminated (last character in array is ‘\0’ null) not writen explicitly in string
    literals

Problem 1.1
a. What do curly braces denote in C? Why does it make sense to use curly braces to surround the body of a function?

  • curly brances define the region of code block.

b. Describe the difference between the literal values 7, “7”, and ’7’.

  • 7 is a int type.
  • “7” is a string. it is ‘7’ plus ‘
  • ‘7’ is a char.
  • double ans = 10.0+2.0/((3.0−2.0)∗2.0);

c. Consider the statement
double ans = 10.0+2.0/3.0−2.0∗2.0;
Rewrite this statement, inserting parentheses to ensure that ans = 11.0 upon evaluation of
this statement.

  • #define squared(x) x*x

Problem 1.2
Consider the statement
double ans = 18.0/squared(2+1);
For each of the four versions of the function macro squared() below, write the corresponding value of ans.

  1. #define squared(x) (x*x)
  2. #define squared(x) (x)*(x)
  3. #define squared(x) ((x)*(x))
  4. return 0;
  • ans1 = 18.0/2+1*2+1 = 9.0+3 = 12.0

  • ans2 = 18.0/(2+1*2+1) = 18.0/5 = 3.6

  • ans3 = 18.0/(2+1)*(2+1) = 18.0

  • ans4 = 18.0/((2+1)*(2+1)) = 18.0/9 = 2.0

Problem 1.3
Write the “Hello, 6.087 students” program described in lecture in your favorite text editor and compile and execute it. Turn in a printout or screen shot showing
• the command used to compile your program
• the command used to execute your program (using gdb) • the output of your program

~/D/C/M/lecture1 [2]> lldb p1-3.o
(lldb) target create "p1-3.o"
Current executable set to '/Users/dudu/Documents/C_Programming/MIT_6087/lecture1/p1-3.o' (arm64).
(lldb) r
Process 869 launched: '/Users/dudu/Documents/C_Programming/MIT_6087/lecture1/p1-3.o' (arm64)
Hello, 6.087 studentsProcess 869 exited with status = 0 (0x00000000) 

Problem 1.4
The following lines of code, when arranged in the proper sequence, output the simple message “All your base are belong to us.”

  1. const char msg[] = MSG1;
  2. }
  3. #define MSG1 “All your base are belong to us!”
  4. 6
  5. int main(void) {
  6. #include
  7. puts(msg);
    Write out the proper arrangement (line numbers are sufficient) of this code.
-4-5-2-7-1-3

Problem 1.5
For each of the following statements, explain why it is not correct, and fix it.
(a) #include ;
(b) int function(void arg1) {
return arg1-1;
}
© #define MESSAGE = “Happy new year!” puts(MESSAGE);

-a no ‘;’

-b the return type of function shall be int but not viod

-c no ‘=’

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/674970.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-19
下一篇 2022-04-19

发表评论

登录后才能评论

评论列表(0条)

保存