Lecture 1 Flashcards
C programming basics
\n
newline
include <stdio.h></stdio.h>
int main (int argc, char** argv) {
printf(“Hello World!\n”);
return 0;
}
what does #include <stdio.h> mean?</stdio.h>
it adds the standard input/output functionality to program (header file)
include <stdio.h></stdio.h>
int main (int argc, char** argv) {
printf(“Hello World!\n”);
return 0;
}
what is int argc?
integer argument for main( )
include <stdio.h></stdio.h>
int main (int argc, char** argv) {
printf(“Hello World!\n”);
return 0;
}
what is char** argv?
char pointer (string array) argument for main( )
include <stdio.h></stdio.h>
int main (int argc, char** argv) {
printf(“Hello World!\n”);
return 0;
}
what does \n mean?
new line
include <stdio.h></stdio.h>
int main (int argc, char** argv) {
printf(“Hello World!\n”);
return 0;
}
what does return 0 mean?
returns 0 when main is done executing, 0 here means the program ran and executed normally
what does GCC stand for?
GNU Compiler Collection
What is gcc?
software program/compiler
ex) you use gcc file.c -o file to compile program in terminal
gcc first.c -o first
what does -o first make?
executable object file named “first”
printf(“%s\n”, “Hello World”);
what does the input/output do here with the format specifier and string?
it puts “Hello World” into %s to satisfy the string format specifier, goes to standard out then prints “Hello World”
how to declare a variable?
data type variable name;
how to declare a variable with initialization?
data type variable name = value;
should you initialize or not initialize when declaring a variable?
initialize, the value assigned if you don’t initialize will not be 0 every time –> it will be assigned to whatever is left in memory
what are the name restrictions for variables?
reserved words (for, malloc, etc), cannot exceed 31 characters
cannot start with a digit
what is allowed for the names of variables?
can contain letters, digits, and underscores
ex) _brent
is case significant with naming variables?
yes, the variable Molly and molly are not the same
arithmetic operations
+, -, *, /, %, ++, –
relational operations
==, !=, >, <, >=, <=
logical operations
&&, ||, !
bitwise operations
&, |, ^, ~, «,»_space;
int main (int argc, char** argv) {
int d = 0;
scanf(“%d\n”, d);
printf(“d = %d\n”, d);
return 0;
}
what does scanf( ) do?
scanf( ) reads characters from terminal, its the keyboard (stdin)
- waits for user at that point in the program to type value in the terminal and hit return (same as scanner in java)
**input
int main (int argc, char** argv) {
int d = 0;
scanf(“%d\n”, d);
printf(“d = %d\n”, d);
return 0;
}
what does printf(“d = %d\n”, d) do?
printf( ) displays the output to the screen,
for “d” –> takes whatever int is available and puts into the format specifier (“%d”)
**output
what is a library function that writes things to to the console?
printf()
*output
what is a library function that gets input/reads what the user puts in the terminal?
scanf()
*input