Joseph Haugh
University of New Mexico
Some slides and code are from Soraya Abad-Mota and Joan Lucas
// Author: Joseph Haugh
/* Forward slash and asterisk to open/close comments */
// Double slash for a single line comment
#include <stdio.h>
int main() {
printf("Hello world!\n");
printf("How are you today?\n");
return 0;
}
.c
.// Author: Joseph Haugh
/* Forward slash and asterisk to open/close comments */
// Double slash for a single line comment
#include <stdio.h>
int main() {
printf("Hello world!\n");
printf("How are you today?\n");
return 0;
}
main
function.// Author: Joseph Haugh
/* Forward slash and asterisk to open/close comments */
// Double slash for a single line comment
#include <stdio.h>
int main() {
printf("Hello world!\n");
printf("How are you today?\n");
return 0;
}
//
/* ... */
printf
function is from the stdio.h
standard library.#
is the preprocessor directive symbol.// Author: Joseph Haugh
/* Forward slash and asterisk to open/close comments */
// Double slash for a single line comment
#include <stdio.h>
int main() {
printf("Hello world!\n");
printf("How are you today?\n");
return 0;
}
printf
= “formatted print”.\n
indicates that a newline should be printed.// Author: Joseph Haugh
#include <stdio.h>
int main() {
printf("He");
printf("llo, wo");
printf("rld!\n");
return 0;
}
\n
is the newline.// Author: Joseph Haugh
#include <stdio.h>
int main() {
printf("Hello world!\n");
printf("How \\are/ \"you\" today?\n");
return 0;
}
"
(double-quote) has a special meaning as a string delimiter.\
(back-slash) has a special meaning as the escape char.// Author: Joseph Haugh
#include <stdio.h>
int main() {
// C is "stream oriented", each statement can
// spill over many lines
printf
(
"Hello world!\n"
)
; // every stmt ends with ;
return 0;
}
printf
statement can span several lines in the source code file.// Author: Joseph Haugh
#include <stdio.h>
int main() {
// C is "stream oriented", each statement can
// spill over many lines
printf
( // strings cannot be split over a line
"Hello,
world!\n"
)
; // every stmt ends with ;
return 0;
}
// Author: Joseph Haugh
#include <stdio.h>
int main() {
// C is "stream oriented", each statement can
// spill over many lines
printf
(
"Hello, " // adjacent strings are
"world!\n" // combined into one string
// we do NOT use "+"
)
; // every stmt ends with ;
return 0;
}
+
operator, as in:
"Hello" + "world"