Main functions, command line arguments and sorting are covered . There are some fun examples of sorting here.
main with argv[] - array of strings
2 chunks of memory
./hello-3 Zamyla with argv[1]
if no name - null
argv[5000] - segmentation fault - touched segment of memory we should not have
error checking - argc==2 any number of arguments beside 2, program will exit string - array of char argv-1 This will print each argument, one per line argv-2 get the jth char in the string sorting- bubble sort, selection sort, insertion sort
Strings and arrays are covered. At the end is a humorous clip from the movie " Spaceballs".
string - char
strlen needs string.h library
not enough memory
null if something goes wrong
check for null
ASCII
integer to char capitalize ctype library functions - toupper and islower https://reference.cs50.net/ info for functions in libraries arrays strings end with \0
More about functions and data types are discussed in the lecture while at the end, is the tragic story about the Patriot missile which was caused by a floating point arithmetic error.
Some short notes here on the lecture:-
can omit curly braces when using one line of code
ssl - encrytpion
regulations about cs50
functions
abstraction - encapsulates
int - returns an integer
implementing get positive int for error checking
int n in the proper braces
prototype
scope - local vs global
data types - char,int, etc
char - 1 byte or 8 bits - 256 total values
int - 4 bytes - 4 billion values
float 4 bytes, double 8 bytes, long long 8 bytes
overflow - 0 comes after 255 for 8 bit values
problems related to float
Right at the end is the touching story of Saroo Brierly which is going to be made into a film soon.
Some short notes here on the lecture:-
make - make object code
./hello
printf is in stdio.h
main - default entry point
paranthesis - holds what is used in printf
double quotes - surround phrase
\n- newline
; - finishing a statement
make - finding the file and convert to object code
clang - compiler
clang hello.c - ls to list contents of directory - a.out
mv a.out hello and then -lcs50
in stdio.h more to printf
escape sequences
%i is a placeholder for integer
types of variables - float, int , char
in cs50 library - string and bool - Getstring etc
condition - if condition { do this }
boolean expression - if condtion and/or another condtion is true needs && and ||
switches - like if else but use cases
loops - for, do while
variables need to be defined
functions
a program to do addition with int x=Getint();
condition-0.c - if, else at first but could not detect zero so if , else if and else used
A history of Paul Allen and Bill Gates and their path to programming the Altair 8800 is read out by two students. String variable is introduced in this lecture.
Some short notes here on the lecture:-
source code
compiler
object code 0 and 1
while (true) - can run forever
for loop - iterate from 0 to 10
variable - store something
counter - counts forever
boolean expressions eg if x>y condition - compares
compiler - eg gcc standard environment linux - a hypervisor cs50 appliance - gedit make - triggers the compiler - saves 0 1and1 in a file called hello ./hello runs
\n is actually new line
string s %s
printf is part of stdio.h
cs50.h library has functions
GetString
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
There is an amusing example of how programs work with peanut butter jelly sandwich in this lecture.
Some short notes here on the lecture:-
variable - container
loop - for
condition - if else
scratch program
statement - eg say hello world, wait for one second, play sound
boolean expression - eg. >, true or false, touching mouse pointer
condition block - if else if else
loops - repeat
variable n
mltithreading
multicolored bulb and binary bulbs