C Notes
C Notes
Commands--
1.dir--This command displays the wide format of matching file names in the same
directory.
2.cd Directory--into the directory
3.cd .. ---out of the directory
REDIRECTING OUTPUT-----
1.Redirecting the terminal output to a new file--using--'>'
dir new.txt>cfile.txt
cfile.txt
2.This redirection symbol overwrites the file when used again.
hostname >cfile.txt
cfile.txt
3.To prevent overwriting, we use '>>'
hostname >>cfile.txt
cfile.txt
REDIRECTING ERROR---
1. error file extension--'.err'
2. '2'-stands for standard error in command prompt.
3. redirecting standard error to an error file
dir hello.txt>cfile.txt 2>output.err
cfile.txt #this displays the usual information
output.err #this displays 'File Not Found'
4. '1'--stands for standard output in cmd
5. '2>&1'---appends the output and the error in the same cfile.
dir 1.txt>cfile.txt 2>&1
cfile.txt
REDIRECTING INPUT--------
sort--takes input from the terminal
sort
start--opens a new file
start notepad p4.txt
to take input from a file--
sort <p4.txt
COMPONENTS OF A C PROGRAM----
1. execution of a c program starts from main function.
2. It can be void main, int main,cat main..-----types of main function.
3. 3.#include<stdio.h>--is very important
4. no issue with indentation,not necessary, not like python
5. we use printf --to print
6. n--newline
7. semi-colon is must be in everyline
8. return--we have to return 0 when using int main
9. when we use void main -- no need to use return 0
10. if 0 is returned, the it means that the program is executed successfully.
11. gcc new.o---to create object file
12. then execute the object file as--- a.exe
PARADIGM ----
FUNCTIONAL----
1.Scheme-It is a branch of lisp programming language.It is a paranthesised list.
2.Haskell--pure functional language used on large scale industrial application.
they are
written in terms of mathematical functions.(Calculus)
3.Miranda-It is mostly implemented on unique systems. It is useful for rapid
prototyping(3-D model for architecture)
LOGICAL------
1.ASP(Active Server Page): It is mainly used on framework on webpage building.
2.Prolog(Programming in logics): It is used in building databases but it is very
difficult to
build input output bases.
3.Datalog(Declarative logical programming): It consists of facts which are the True
statements under the datalog deduced from the known facts.
OOP(Object-Oriented)----
ex--python,Java,C++
-----------------------------------------------------------------------------------
---------
-------------TIOBE index---------
(The Importance Of Being Earnest)
TIOBE index for March 2023:
1.python
2.C
3.Java
4.C++
5.C#
APPLICATIONS OF C/C++----
1.Linux Kernel-C
2.Adobe systems-Photoshop &Illustrator
3.Mozilla-C++
4.Bloomberg-billionare website used for tradinig--c &c++
5.Callas Software
6.Symbiam OS-mobile os back in 2003, Nokia once preferred this.
Kernel: a part of OS ,an intermediator between os and backend(hardware and the
processor).They are written in C.
stdio.h---standard input output header file.
%d--format specifiers, this is for integer
__STDC_VERSION----known as MACRO--used to know the compiler status and the
compiler version.They are predefined statements.
gcc -v : this gives the version of gcc in the command terminal
3.Logical Error------
i. when you do not get the expected output.
4.Linking error---
i. here the program is executed/compiled successfully but executables(a.exe) are
not
generated. simple.o (obj) files are already created but the error occurs when
linking these
files.
ex: 1. incorrect header file
2. wrong function prototyping
3. when main is changes to Main
INPUT/OUTPUT FUNCTIONS--------
FORMATTED OUTPUT FUNCTION--prinf()
Syntax: int printf(const char*format,..)
1. On success---returns number of characters successfully written on the output
2. On failure---a negative number is returned
IDENTIFIERS--
1.It is used to identify a variable,keyword,function or any other user defined
item.
2. It starts with (A-Z),(a-z),_0/more elements,_(digits[0-9])
3. C programming does not allow few punctuation characters such as #,@,% within
identifiers.
ex:int d=68;//variables
int d_section=68; //identifiers
VARIABLES---
1.A variable has name,location,type,life,scope and qualifiers
scope-local,global
type-int char float double
qualifiers-signed and unsigned
KEYWORS---(32 in C)
1.they are the identifiers that have a special meaning in C,they cannot be used as
variables.
ex: int, main, float,double,sizeof,struct,enum,bool,gets,fgets,etc.
OPERATORS----
set bit-
clear bit-
toggle bit-
-------------------
TERNARY OPERATOR--
Syntax: (condition)? statement if condition is True: statement if condition is
False
------------------
L value R value-
L value-unknowns
R value -knowns
------------------
LANGUAGE SPECIFICATIONS--
----------------------------------------------------
CONTROL STRUCTURES-
SELECTION STRUCTURES--
Syntax:
1. if
if(e1)
<block>|<stmt>
2. if-else
if(e1)
<block>|<stmt>
else
<block>|<stmt>
3.if-elseif-else
if(e1)
<block>|<stmt>
else if(e2)
<block>|<stmt>
else
<block>|<stmt>
4.switch
switch(expression)
{
case integral constant:<stmt>break;
case integral constant:<stmt>break;
default<stmt>;
}
5.for
for(e1;e2;e3)//e1:initialisation,e2:condition,e3:modification
<block>|<stmt>
6.while
while(e2)
<block>|<stmt>
7.do-while
do{
<block>
}while(e2);