Thursday, August 27, 2020

if, else if, else

if (x<y)
{
printf("x is less than y\n");
}
else if (x>y)
{
printf("x is greater than y\n");
}
else
{
printf("x is equal to y\n");
}

"==" equality operator ; "=" assignment operator

C programming

if, else if, else if

if (x<y)
{
printf("x is less than y \n");
}
else if (x>y)
{
printf("x is greater than y \n");
}
else if (x==y)
{
printf("x is equal to y \n");
}


C: no semicolons after condition statements (semicolons after some kind of "action")

Source: Harvard , CS50


if else

if (x<y)
{
printf("x is less than y \n");
}
else
{
printf("x is not less than y \n");
}

Condition:

if (x<y)
{
printf("x is less than y\n");
}


Increment by 1 : three forms

counter = counter +1;

counter += 1;

counter++;


counter++;

increment by 1

counter += 1;

increment by 1


counter = counter + 1 ......... "=" assignment operator

assignment operator "="

make - included in Linux, MacOS, and Windows these days

the make program is now included with these operating systems

make string

when you type this command, the program "make" will look for a file called "string.c" to compile into the executable "string"


if you type the command "make hello" , the program make will look for a file called "hello.c" and compile it into the executable "hello"


[Source: Harvard, CS50]


clang -o string string.c -lcs50

in addition to " #include <cs50.h> "

you also have to "-lcs50"

where "l" stands for  "link"



[Source: Harvard, CS50]