0% found this document useful (0 votes)
7 views

Coding notes

Uploaded by

shizatalpur0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Coding notes

Uploaded by

shizatalpur0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Tab 1

Coding Notes

Basics:

●​ We use different languages for different purposes:

For Web development:


HTML(structures your content),
CSS (styles it),
JAVASCRIPT(adds interactivity)

For Mobile Applications:


IOS ~ Swift
Android ~ JAVA, Kotlin
Both ~ react native, flutter

For Game development:


C# , C++

For A.I :
Python

Let's begin with C language first:

Important terms you need to know while coding:


●​ In programming, an algorithm is a set of instructions
that a computer follows to solve a problem or perform
a task.
●​ At first it's input and then algorithm is a set of
instructions (the process) given by programmer which
machine follows and gives output
●​ Logical operators used in conditionals (&&~ and)
( || ~ or )
●​ If (! That means check the condition is true or not if
it's not then also proceed the code inside
●​ Now these are format specifiers
●​ Float (%f)
●​ Char (%c)
●​ Array of char( % s)
●​ Int(%d)
●​ In Arithmetic operators: if our division answer is in
decimal then it will only give a whole number to get a
right answer
you have to change int to float for the divisor and the
variable which is performing action
e.g float z = x / y int x = 5; and float y = 2; or
float z = x / ( float ) y; int x = 5; and int y = 2;
●​ We use return 0; for exit of our program like when we
are done with our code and our code has been
executed it will exit.
●​ We use semicolons when we are done with a
statement. They are used to indicate that our
statement is completed.
●​ We use modulus % to get the remainder in division.

COMMENTS AND ESCAPE SEQUENCES:


●​ To add comments we must use // for one line
●​ To add comments in multi lines do this /* and it ends
with /* . We use these comments like notes in our
code, they are completely ignored by the compiler, it’s
like it is an explanation to what we have written in our
code so that when anyone including us view our code
they will easily be able to grasp the concept behind it
without encountering any trouble.
●​ Escape sequences are different characters consisting
of a backslash\ they are followed by a letter or
combination of digits, they are used to specify actions
within a line or string of text. For instance \n is used
to move to the next line while \t is used to move only
one tab ahead. But when you are coding and you want
to quote someone then you write like this:
(“\”You drew Stars around my scars\” - Taylor
Swift”); or you can just replace double quotes with
single quotes

VARIABLE
●​ Variable (something which changes)
●​ The variable stays the same but the value inside
it changes.Variable store values which vary, are
not permanent
●​ In computing, a variable is a piece of memory
that stores a value that can be changed
●​ To create a variable we first need to declare it
and then initialize it
●​ In declaration we need to mention data type first
and then name the variable which must relate to
the values we are assigning the variable.
int x; int is the data type while x is the variable.
●​ In initialization we assign the value to the
variable.
x= 123;
We can even do those both steps together:
int x = 123;

●​ Different Data types:


●​ Float ( decimal values 6-7 digits accurate) %f
●​ Double (decimal values 15 - 16 digits, more
precision or accuracy)%lf and if we want to print
more values or specific values we should add 0.1
if we want only one digit after decimal point
E.g 99.9
●​ String ( letters , alphabets, Words)
●​ Int ( Whole numbers)%d
●​ Array ( letters and numbers together)
●​ Char (only one character)%c and Char is
initialized within single quote
●​ Char characters within double quotes and char
(name) [] %s
●​ Booleans( true, false) to include that in our code
we should use the (stdbool.h) library. 1 = true, 0
= false. %d
●​ We can store numbers from -128 to +127 in Char
or signed char
E.g char c = 100;%d or %c (or you can convert
them into a character through ASCII chart).
●​ Unsigned char( stores numbers from 0 to +225)
%c (or you can convert them into a character
through ASCII chart) or %d
●​ We use short int to store numbers (from
-32,768 to +32,767) %d or you could just use
short.
●​ We can use unsigned short int to store
numbers(from 0 to +65,535)%d or you could also
just use unsigned short.
●​ Int stores from ( -2,147,483,648 to +
2,147,483,647).%d
●​ While unsigned int ( 0 to +4,294,967,295) %u ,
We don't mention long here because it's
unnecessary.
●​ Long long int stores ( -9 quintillion to +9
quintillion)%lld
●​ Unsigned long long int ( 0 to +18 quintillion)%llu
and we should add u at the end of all integers we
wrote.
●​ In format specifier if we want to add width(%n or
%- for left align)
E.g 5.75 then %8.02f
Then …..5.75
If left align then %-8.02f
Then 5.75…..
●​ Constant:
it's a value which can't be changed, it's a
constant value, so if you don't want anyone to
change the value then add const In Front of your
variable and keep the variable name in Capitals
it's not necessary but it keeps it distinguished
from others. It can't be altered by the program
during execution.
E.g const float PI = 3.142;
AUGMENTED ASSIGNMENT
OPERATORS:
●​ C allows you to combine arithmetic and
bitwise operators with the = symbol to form
augmented or compound assignment
operators. They are like a shortcut for
statements where an operator takes a
variable as one of its arguments and then
assigns the result.
●​ E.g x = x+1
// x+=1
0r x = x-3
// x-=3
X = x*4
// x* = 4
X = x/2
// x/ = 2
X=x%3
//x % = 3

Logical operators: && and


|| Or
! Not
To add booleans we should add stdbool.h header file.
True represents 1, and false represents 0.
We use them in else if statements to either add a
condition like in case of and && if our both conditions
are true then the code will be executed while if it’s
or|| then only one condition must be true. While on
the other hand ! not it means if the given condition is
not true then only the code will be executed.
Arguments and Parameters:
The values that are declared within a function when the
function is called are known as an argument. The variables
that are defined when the function is declared are known as
parameters

You might also like