Posts

Operators in C

Image
  //operators in C programming language //Operators: a symbol used to perform operations in given programming language //Types of operators in C language     /*1. Arithmetic Operators       2. Relational Operators       3. Logical Operators       4. Bitwise Operators       5. Logical Operators     */ //--------------------------------------- //Arithmetic Operators     /*(+): addition       (-): subtraction       (*): multiplication       (/): division       (%): modulus - gives remainder       */ //--------------------------------------- //Relational Operators     /*(==): is equal to       (!=): is not equal to       (>): greater than       (<): less than       (>=): greater than or equal to       (<=): less  than or eq...

Variables and Data Types in C

//variables in C //variable: A name given to a memory location is called variable //declaring variable: type variable_name; //rules for defining a variable in C     /*1. can contain alphabets, digits and underscore(_)       2. a variable name can start with an alphabet and underscore only       3. can't start with a digit       4. whie space and reserved words are not allowed to give name of a variable       */ //Data types in C     /*1. basic data type: int, char, float, double       2. derived data type: this type of data types are created or derived by using basic data types                             array, pointers, structure, union       3. enumeration data type: emum       4. void data type: void     */ #include <stdio.h> int main () {     printf ( " %lu " , s...

Tokens in C

//basic syntax of a C program // a C program is made up of the collection of tokens // Token: smallest unit used in a C program is called token #include <stdio.h> int main () {     int     a // token (identifier)     ;     a     = // token (operator)     100 ;     printf     (           "softwareharaish" //token (string literal)     )     ; //token (symbol)     return //token (keyword)     0 //token (constant)     ; } // in the above c program I breaks the program into individual tokens // types of tokens i C program     /*  1. keywords: reserved words which has a special meaning in c program ()         2. identifiers: name of functions, variables ets to identifie                         (panctuators are not allowed to make id...

Steps taken by a compiler to execute a C program

//steps taken by a compiler to execute a C program /*  1. pre processing: i) comments removal                        ii) macros expansion                        iii) #files inclusion                        iv) conditional compilation     2. compilation: converts to assembly level instructions     3. assembling: converts to machine level instructions     4. linking: linker combine all machine level instructions                 to create an executable file that is .exe file*/ //to understand better how compiler works follow the below step /* A) execute "gcc -Wall -save-temps file_name.c" on vs code terminal     u will get 4 extra files in explorer this files will show u how compiler works         1. file_name...

Command line utility

#there are two types of command line arguments are there #1. positional arguments #- we can give value arguments directly in WPS (windows powershell) #- cant skip any value argument #- expected command in WPS for command line argument program execution ( 4 6 add [note:cant change position]) #2. optional arguments #- we have to give value arguments in WPS with (--argument_name argument_value) #- we can skip any value argument #- expected command in WPS for program execution (--number1 4 --number2 6 --operation add [note:can change position]) import argparse #python built in library import sys if __name__== '__main__' : parser=argparse.ArgumentParser() #parser object # 1. positional arguments # using add_argument function or attribute adding arguments '''parser.add_argument("num1", help="first number") parser.add_argument("num2", help="second number") parser.add_argument(...

'is' vs '==' in python

# '==' : value equality-two objects have the same value # is : reference equality- two references refer to the same object a=[ 1 , 2 , 3 ] b=a #two references refer to the same object(b is not the copy of a) print (b==a) print (b is a) c=a[:] #two references refer to the two different object(now c is the copy of a) print (c==a) print (c is a)

Raise keyword in python

#raise is a built-in keyword used to raise exception # visit all built-in Exceptions and understand name= input ( "enter u r name:" ) if name.isnumeric(): raise Exception ( "numbers r not allowed" ) #here we used raise keyword