Programming Fundamentals Lec1
Programming Fundamentals Lec1
Any electronic device that take input, process it and also store it in memory and in the last stage give us the output
of our given input is called computer.
WHAT IS PROGRAM?
Programs Are The Instructions That We Give/Write Computer To Perform Any Specific Task Is Called Program.
Computer cannot understand our language so if we want to solve any task with the help of computer we need to
write a program.
WHAT IS PROGRAMMING?
Programming is a technique used to write any program.
&
ART: Programming have different & creative ways to write any program.
If we want that computer perform any task that we want we have to write a program with techniques that is called
programming.
PROGRAMMING LANGUAGES:
Now we have to talk about the Source of Communication to Computer that is called programming languages.
Low-level languages:
1. Near to computer.
2. Deep knowledge of hardware is required.
3. Easily to understandable for hardware but it is difficult for programmers to write any program.
Machine Language:
1. Actually consist on Binary numbers that is difficult and not modifiable for programmers.
2. Deep knowledge of hardware is required.
3. Difficult to write or read, Debug or troubleshoot program.
Assembly Language:
1. Consist on Mnemonics (Symbolic Codes).
2. Short codes that have binary no in backend. Like: move (111111111011).
3. Now the code is readable, modifiable and easy foe programmers.
High-level language:
1. English like language.
2. Near and understandable for humans and far from computer.
3. In High-level language it is too easy to write program for programmers but difficult for computers to
understand so we need processors (translators) that convert source code(high-level language) into object
code(Machine language).
Language Translators:
Assembler:
A translator or processor that convert assembly language into machine language.
Compiler:
A translator that converts whole statement of High-level language into machine language.
Interpreter:
A translator that converts single line statement one time of high-level language into machine language.
RUNTIME ERROR:
That occur during execution or when the given instruction is out of range of computer, computer does not
execute the program.
LOGICAL ERRORS:
That occur when we do error in planning our program logic, difficult error to find.
PRE-PROCESSOR DIRECTIVES:
Every directive is a one-line long command which contains the following: # (hash) symbol (All
the preprocessor directives in C++ start with the # (hash) symbol). A pre-processor instruction after
the # (hash) symbol. For example, #include, #define, #ifdef, #elif, #error, #pragma etc.
As its name shows pre-process means before the compilation of program pre-processor directives are added
to our program. There are two type of pre-processor directives:
#include: to include any other file or library to your program.
Syntax:
#include<stdio.h>-------------------------angle brackets if we are adding a file that is
provided by our IDE or compiler (when we download c++ IDE the folder include is created and all the pre-
made library or file or functions is saved on that folder) like: <iostream>, <stdio.h>, <conio.h>
#include” myfile.h” -----------------------------------------double quotes if we are using the file or library that we
created.
#define: use to create macros like:
Syntax: #define five 5 .the value of five is 5, means that in my program replace every word five with 5.
KEYWORDS IN C++:
Keywords are the pre-defined words in a language that have some specific meaning. According to structure C
language have 30 pre-defined keywords in it and now C++ have 90 keywords in it.
For, while, do
RESERVED WORDS IN C++:
Now if we talk about reserved words we can say that the reserve words are not the part of programming language or
c++ but it is the part of header or library.
Like if we have a reserved word “string” that is defiened in library “namespace std”
OUTPUT FUNCTIONS:
Output functions are those functions that help us to print any statement on console (output) screen. There
are too many output functions in c++.
1. Printf:
use in C. As its name shows print function it is pre-defined in stdio (standard input output) library.
SYNTAX:
Printf(“hello world”) no matter what we write in these double quotes will be printed on the
console screen except Escape sequence and format specifiers.
2. Cout:
use in C++. The most popular way to print statement it is pre-defined in iostream library
SYNTAX:
Cout<<”hello”;
These << means stream insertion operator in fact in our programming language we have a library/
header file iostream, & in iostream this operator(<<) is overload or added. Means that left operands
Is cout and operator is << and right operand is any message that we want to print.
3. cprintf:
Color print function is help you to add colors on the console screen it is pre-defined in conio library.
SYNTAX: OUTPUT:
Textbackground(black); hello
Textcolor(red);
Cprintf(“hello”);
TRICKS:
YOU CAN USE YOUR NAME OR ANY WORD INSTEAD OF COUT AND IT WILL WORK AS COUT FUNCTION
LETS SEE HOW IT WORKS.
Cout function is a reference of ostream class or library (output stream) that is pre-defined in our compiler
means that ostream &cout is already have a reference with each other in our language. Yani jab bhi ham
cout likh kar kuch bhi print karwatey hen tou pata chalta hey key cout bhi aik ostream jesi hi chezz hey jisko
ham changing karke use karskte hen.
VARAIBLES IN C++
Varaiables are the named memory location in RAM which contain some value which can be changed.
Varaibles are the container that contain some values.
SYNTAX:
Datatype varName;
DATATYPE IN C++
Datatype define which of data youre working with. There is different built-in datatypes are provided in our
programming language.