I l @ ve RuBoard |
They are called functions.
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?";.
A semantic error is one of meaning. Here's an example in English: "This sentence is excellent Italian." Here's a C example:
thrice_n = 3 + n;
Line 1: Begin the line with a # ; spell the file stdio.h ; place the filename within angle brackets.
Line 2: Use () , not {} ; end comment with */ , not /* .
Line 3: Use { , not ( .
Line 4: Complete the statement with a semicolon.
Line 5: Mr. I.B.M. got this one (the blank line) right!
Line 6: Use = , not := for assignment. (Apparently, Mr. I.B.M. knows a little Pascal.) Use 52, not 56, weeks per year.
Line 7: Should be
printf("There are %d weeks in a year.\n", s);
Line 9: There isn't a line 9, but there should be, and it should consist of the closing brace , } .
Here's how the code looks after these changes:
#include <stdio.h> int main(void) /* this prints the number of weeks in a year */ { int s; s = 52; printf("There are %d weeks in a year.\n", s); return 0; }
Baa Baa Black Sheep.Have you any wool?
(Note that there is no space after the period. You could have had a space by using " Have instead of "Have .)
Begone! O creature of lard!
(Note that the cursor is left at the end of the second line.)
What? No/nBonzo?
(Note that the slash ( / ) does not have the same effect as the backslash \ ; it simply prints as a slash.)
2 + 2 = 4
(Note how each %d is replaced by the corresponding variable value from the list. Note, too, that + means addition and that calculation can be done inside a printf() statement.)
int and char ( main is a function name , and = is an operator).
printf("There were %d words and %d lines.\n", words, lines);
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 can't be 2 because by the time you say a = b; , b has already been changed to 5.
I l @ ve RuBoard |