Section 1
Section 1
Think.
Pair.
Share.
● Why are we using C?
● How can we read and write code that includes
variables, conditionals, and loops?
● Why do we care about data types?
● What does it mean to compile a C program?
● Why are we using C?
● How can we read and write code that includes
variables, conditionals, and loops?
● Why do we care about data types?
● What does it mean to compile a C program?
● How many years will it take to double our llamas?
Part 1 Variables and Types
Input and Printing
Variables
calls
4
Variables
4
Variables
4
assignment
operator
Variables
"Create an integer variable named calls that gets the value 4."
Variables
int x = 50; x
50
Variables
int x = 50; x
50
65
01000001
char
'A'
01000001
Variables
int calls = 4;
value
Storing return values
"Create an integer variable named calls that gets the value 4."
Printing values
int calls = 4;
printf("calls is %i\n", calls);
Printing values
int calls = 4;
printf("calls is %i\n", calls);
format code
Printing values
int calls = 4;
printf("calls is %i\n", calls);
if (calls < 1)
{
printf("Call more often!\n");
}
conditional
if (calls < 1)
{
printf("Call more often!");
}
if (calls < 1)
{
printf("Call more often!");
}
executed conditionally
if (calls < 1)
{
printf("Call more often!\n");
}
else
{
printf("Thanks for calling!\n");
}
if (calls < 1)
{
printf("Call more often!\n");
}
else mutually exclusive
{
printf("Thanks for calling!\n");
}
int i = 0;
while (i < 10)
{
printf("%i\n", i);
i = i + 1;
}
initialization
int i = 0;
while (i < 10)
{
printf("%i\n", i);
i = i + 1;
}
Boolean expression
int i = 0;
while (i < 10)
{
printf("%i\n", i);
i = i + 1;
}
int i = 0;
while (i < 10)
{
printf("%i\n", i);
i = i + 1;
}
incrementation
int i = 0;
while (i < 10)
{
printf("%i\n", i);
i = i + 1;
}
for (int i = 0; i < 10; i++)
{
printf("%i\n", i);
}
initialization