1 / 14

Programming Fundamentals Basics

covered topics:<br>1. preprocessors<br>2. define<br>3. data types<br>4. variables<br>5. comments<br>6. statement<br>7. token<br>8. operators<br>9. initialization & declaration

Download Presentation

Programming Fundamentals Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Fundamentals Muhammad Awais

  2. Preprocessor Directive • Instructions given to program before execution for some specific tasks. • Used for tasks such as file inclusion and macro definitions.

  3. Preprocessor Directive • Include Directive (#include): Used to include the contents of another file in the current file. • Header file : File containing standard Library (predefined) Functions to perform different task • Many Header files for different purposes • Extension of header file is .h ( in older versions) #include <iostream> (provides functionality for input and output operations in C++ programs) • Define Directive (#define): Used to define macros, which are text substitutions. For example: #define PI 3.14159

  4. Input & Output • Streams are used for input and output operations in C++ programs. They provide a uniform interface for reading from or writing to various types of devices, such as the console, files, and other I/O devices. • There are two main types of streams in C++: • Input Streams: These streams are used for reading data from a source, such as the keyboard or a file. The standard input stream cin is an example of an input stream. • Output Streams: These streams are used for writing data to a destination, such as the console or a file. The standard output stream cout is an example of an output stream. Example : std::cin>> Marks; std::cout<< "Hello world”;

  5. C++ Tokens Token : Lanaguage elements to form a c++ statement. • Identifiers : Names used to Identify any variable, constant or keyword • Standard Identifiers : Reserved Words or Keywordswhich have predefined meanings in the language. int, main, if, return, etc. These are predefined words in C++ with specific meanings. • User Defined Identifiers : Names given to variables, functions, classes, etc., defined by the programmer. number, message, PI, MAX_VALUE, sum. These are names given to variables (number, sum), constants (PI, MAX_VALUE), and functions (main).

  6. C++ Tokens Rules for naming User defined Identifiers : • Reserved words can’t be used . • Short and descriptive. • Unique. • Up to 31 characters long. • Contains alphabets , numbers . • Start should be always from alphabet or number . • No spaces between name can use underscore instead of spaces.

  7. C++ Tokens • Operators: Symbols used to perform operations, such as arithmetic or logical operations. =, +, >. These symbols are used to perform operations like assignment, addition, and comparison. • Punctuation: Symbols used for punctuation, such as semicolons, commas, braces, etc. {, }, ;, <<, (). These symbols are used for syntax and structure, such as braces for blocks, semicolons to end statements, and parentheses for function calls and expressions. Note : every instruction in c++ ends with ; ( semi colon ) which helps the compiler to understand where a instruction is starting and ending. Example : std::cin>>b; std::cin>>c; int a = b+c;

  8. C++ Statements • Statements are individual instructions that make up a program. • Compound Statements (also known as blocks) are groups of statements enclosed in curly braces {}. They can be used anywhere a single statement is expected.

  9. C++ comments • Comments are non-executable parts of the code that are ignored by the compiler. They are used to improve code readability and understanding. • Types of comments include single-line comments (//) and multi-line comments (/* */).

  10. C++ character set • The C++ character set consists of letters (both uppercase and lowercase), digits, special characters, and whitespace characters.

  11. Main Memory • Every data for processing is stored in memory • Memory Allocation & Deallocation is done for effeciency • Memory addresses are unique identifiers assigned to locations in the computer's memory where data or instructions are stored. Every byte of memory in a computer system has an address, which allows the CPU and other hardware components to locate and manipulate specific data or instructions.

  12. Constant Constants are fixed values that do not change during the execution of a program. They can be of various types such as integer constants, floating-point constants, character constants, and string literals. • Integer Constants: Whole numbers without any decimal point. • Floating-point Constants: Numbers with a decimal point or in exponential form. • Character Constants: Single characters enclosed in single quotes, like 'a', '5', etc. • String Literals: Sequences of characters enclosed in double quotes, like "Hello, World!". PI, MAX_VALUE. These are fixed values that do not change during program execution. const int MAX_VALUE = 100; const float PI = 3.14159; const char NEW_LINE = '\n';

  13. Variable • Named memory spaces. • Every variable has a datatype, name , value and memory address . • Variable value is not fixed it may change through out the program. • Used for storing data taken as input or during processing

  14. Declaration & Initialization • Declaration : It tells the compiler about the existence and type of the identifier but does not allocate memory or assign a value to it. Declarations are necessary before using identifiers in the program. int a ; • Initialization : It is the process of assigning an initial value to a variable at the time of its creation. It can be performed at the same time as declaration or later in the program. Initialization ensures that variables have well-defined values before they are used. int a ; a = 10 ; Or int a=10;

More Related