In your notebook… Purpose: What types of data can we store in C In your notebook… Purpose: What types of data can we store in C? Warmup, Copy these two lines to your notes and then answer in a sentence to tell what each line does. This is a shortcut way to combine those two lines into one line:
what happens? works okay? Download twoChars.c from our web page. Compile and make it work. Copy this table to your notebook. Try each pair above in lines 9 & 10 of your program. Write the results into your notebook. X what happens? works okay? Y 68 ‘D’ 101 (101+1) ‘#’ “#” “boy” “girl”
This is CS50 AP. an introduction to the intellectual enterprises of computer science and the art of programming Unit 1 Module 3 © David J. Malan, Doug Lloyd
variable names in C, underscore preferred style, camel case is okay too. variable name length is between 1 to 32 characters can have alphabet, upper and low er case, underscore and digits. but cannot start with a digit no spaces in the name!!
data types
native types
int 50 -10 8529923 Stands for integer 50 -10 8529923 Stands for integer Holds integers between -32768 and +32767
char ‘a’ ‘Z’ ‘?’ ‘\n’ Holds characters such as ‘x’ and ‘*’ Must have single quotes only Or Since the computer stores it as an ascii, The actual ascii number
float 0.0 -50.505 33.3 3.14159265
double long int Holds extremely large/small floating point values To avoid math rounding problems, less discarded digits Holds extremely large positive and negative integers
const
custom CS50 types #include <cs50.h>
booleans (bool) true false
string “A” “Hello, world!” “Hello, world!\n” “This is CS50.”
sizes char 1 byte bool int 4 bytes float string double 8 bytes long long see more at https://en.wikipedia.org/wiki/C_data_types
later this year… user-defined types typedef, struct, enum
Conversion character Description %d integer %f floating-point %c character %s string Example: printf(“My dad’s name is %s and he is %d years old”, x, y);
This is CS50 AP.