c++ coding

       Gds group 🌟

 The C Programming              Language

The C Programming  -:  is a computer programming book written by Brian Kernighan and Dennis Ritchie, the latter of whom originally designed and implemented the language, as well as co-designed the Unix operating system with which development of the language was closely intertwined. The book was central to the development and popularization of the C programming language and is still widely read and used today. Because the book was co-authored by the original language designer, and because the first edition of the book served for many years as the de facto standard for the language, the book was regarded by many to be the authoritative reference on C.
C was created by Denni Ritchie at bell labs in the early 1970s as an augmented version of men thompson's B, Another Bell Labs employee, , had written the first C tutorial,and he persuaded Ritchie to coauthor a book on the language.Kernighan would write most of the book's "expository" material, and Ritchie's reference manual became its appendices.
 
Syntax - : 
# include<stidio;h>
 It's a standard liabrary , standard input/output  hear h is a meant  by header file # include <conio;h>
In a way in mathematics have a formulas to solve it 
The same way C language has syntaxl hu strategy to write program # is i have link to standard input/output header file through
" Conio h "  is console input/output. If you have to perform any console you to give a text include
Void main( ) is a return type void main and

the entry point for execution in C program. The void is a keyword that represents function will not return anything but a void value. Main is the name of the function and () represents parameter list that can be passed to function in this case nothing is passe  
Void means nothing or empty. void main() - means here main() return nothing.int main() - means here main() returns an integer value.
Transcribed image text: #include #include <stdio.h> <string.h> void pe6-7( void ) char input[81 int i; int length; printf( "Enter a word: ")i scanf ("%s", input ); length = strlen ( input); for (i length - 1; i >= 0; i--) printf("%c", input [1]): printf("In"
Void main ( )
     Printf("    ") is used to get output
     Scanf( "   ") is used to give input
Basically it so important 
     Printf ("    ") and scanf ("    ") both are predefine function
 
Now the things are concerned that how to install TURBO " C  at where you work 
First you have to visit on Google browser and search // turbo C downloaded then Press  enter 
Void main( )
       { 
           Printf ( " C programming");
           Getch( );
        }
Getch is used to holding screen
When The coding is completed 
To run it press Ctrl + F9
Or go to compile and click run tab
 
What is the keywords- :  keywords is a reserved word whose meaning already find in the compile 
Type of keywords -: 32 
 
   Int            Extern          For            Size of 
   Chat         Go to            Const       Short
   Float        Break            If               Struct 
   Double     Continue     Else           Union
   Void.        Do.               Type of      Enum
   Auto         Switch         Signed      volatile
   Register   Case            Unsigne    Default
   Return      while            Statics      Long
 
  Note  -: we can't use any keywords as a variable and  as a method Name for own purpose task  
Like -
           Int float = 10 ;
Here we can't use of float as a variable the because float is a keyword 
If I write double (i) is a error prosess

          Void main ("      " );
             {
                   Printf   ("      ");
            }  

What is the data type -:  data type is a specific size & type of value that can be stored in variable
         
         Int a  = 10 
         Size of ( a );

Two types of data type   
        1 -: primary  data type    
        2 -: secondry data type 
      
1 -: primary  data type -: 
         a-  int ( 2 bytes  -32768 to + 32767)
         b- char(1 byte -128 to + 127 ) 
         c- float (4 bytes & 1.175E^-38 to 3.4E ^-39)
        d- double (8 bytes) 
        e-  void (0 byte)

 2 -: Secondry  -: 
         Array 
         Pointer
        Structures
         Union 
All Secondry type have no file of fix size  specelly  its size depends on its programming

How to find out size of data type -: 
As title // find out data size type "
     
        Int a ;
        Printf ( " %d ") ; 
                                            Output  xxxxxx
 
Clrscr ( ) ; is used to remove first output results
         For int %d. Or %l
         For float % f is used 

Int a = 10 
{       
         Printf ("%d", ; size of (a) ; or 
         Printf(" %d",a) ;
         Getch() ;       
}
                                    For  Output press Ctrl F9


 What is Variable  -:  is a memory location where we store data  
for store any data in this location
 The diagram represents the name, type, address, and value of a variables. The value is typically represented by an arrow pointing to the referenced object. For an object it is represented the class of which the object is an instance, and the state, i.e., the values of its properties. The diagram on the left shows the actual addresses of memory locations, to clarify the notion of object reference. In fact, in Java the addresses of objects are never represented explicitly, i.e., one is not interested which is the memory location that is actually used to store an object (see diagram on the right). Often, we will also omit the type of a variable, since it typically coincides with the type of the referenced object (note that this is not always the case, due to inheritance - see Unit 4).

Example: the situation in memory after the execution of the statements

String s,t,u;
s = "xxx";
t = "yyy";
u = t;
is shown in the following diagram.


next up          int  a ; is // globle variable
          Void main ( )
               {
                       Int b ; is a local variable
                       Static C ; is a static variable
                }

            Clrsce ( );
            Printf ("%d",a);
            Printf ("%d",b);
            Printf ("%d",c);
            Getch( ); 
                         0287600
 To get  Output prss Ctrl+F9
 Or go to compile click on run
This out come come in rows is visibly good 
If this result would come in columns then it's be understandable results 
Like  -:      0
                 28760
                 0
I have to add (" %d\n ");
            Printf ("%d\n",a);
            Printf ("%d\n",b);
            Printf ("%d\n",c);
            Getch ( );
                                    0
                                    28760
                                    0
What is identifier    -:        identifier is refer to the name that is use to identify variable function and so on    .
Example   -
              Int a;
              Int b; 
Both are variable is identifier but all identifier are not variable
              
              Void sum( );
              Void Fun ( );
Functions are identifier but all identifier are not function 

What is the operator -:  operator is a symbol that tells the compiler to perform mathematical and logical task

Type of operator -: 
1 -: Arithmetic operetors (+, - , * ,% , ÷ )
2 -: Relational operators (>, < , ! , <= , >= )
3 -: Logical operators (& , : , ! ")
4 : Increament/decreament operators (++ ,-- )
     (a) -: post increament/post decreament
               (a ++ , a- -)
     (b)-:  preincreament / predecreamen
               (++a , - - a)
5 -: ternary operators ( ? , ; )
6 -: assignment operators ( = )
        
                 Int a = 10;
                 Printf("%d\n",a);       //10
                 Printf("%d\n",++a);  // 11
                 Printf("%d\n",a++);   // 11
                 Printf("%d\n",- - a);   // 11     - 12
                 Printf("%d\n",a - -);   // 11
                 Printf("%d\n",a);       // 10
                 Getch ( );
                
                                  10
                                  11      
                                  11
                                  11
                                  11
                                  1o     . output come 
Compound assignment operators is 
                    a+ = 10
Simple assignment operators is 
                     a = 10
According to compound assignment operators
                    a+ = 10
                     Printf ( "%d\n",a);
                     Getch(  );
                      
                     Output is 20 
All compound assignment operators  have  double valuation of itself in condition (" a+ ")

Ternary operators work with two variables  Here two variables    
                     Int a = 10  , b = 20

                      Printf ("%d\n",(a>b)?(a:b);
                      Getch( );

                      Here  Output is 20 
Through ternary operation two variables are comparisoned each other  ,the variable having more valuation will be printed on screan
If i a change into 50  then first statment will be true and 50 printed   

Logical operators  -:   
                        Int  a= 60   b= 30

                        Clrscr( );
                        Printf ("%d\n",(a>b)&&(a>b));
                        Printf ("%d\n",(a>b): : (a<b));
                        Printf ("%d\n",! (a>b);
                         Getch( );
                      
 Out printed   as  1
                              0 
                              0 

Here first statement is true and printed 1
Rest of both are false       
There by printed o ,o next to

 Conditional statements     -:    
                          
 1 -: if statment
 2 -: if else statement ( is used in 2 condition)
 3 -: if else statement ( is used in more than 2 condition)
 4  -: Nested if statement (is used in such conditions when a condition is under another condition 
 5 -: Switch statement

What is if statement -:  if statement is used  when want to test a condition 

Syntax : 
              If ( condition)
                   {
                         || Statement ;
                    }
                
              Void main ( ) 
                    { 
                        Int password ;
                     }
         
              Printf (" Enter password , ! ") ;
              Scanf( "%d",& password) ; 
              
              If( password ==24484)
                    {
                          Printf ("welcome") ;
                     }
                      Printf ("main function end")
                      Getch( );
If given statement "password 24484"  is true 
Than print.   " welcome  "
Otherwise    " main function end "
Here given first statement is true ,"welcome " will be printed 


 If else statement -: it is used to execute two statements either if statement or else statement for a single condition 
Syntax : 
                 If ( condition)
                       {
                              || Statement 1 ; 
                        }   
                  Else
                        { 
                              || Statement 2 ; 
                        }
Algorithm -: 
                 Step 1 -:  start
                 Step 2 -: input age
                 Step 3 -: if age greater than 18 years
                 Step 4 -:  stop

                  Int  age ; 
                  Clrscr( ) ;
                  Printf ("Enter age, !\n") ;
                  Scanf( " %d",&age);

                  If  (age >=18)
                        {
                              Printf(" eligible for vote") ;
                         }
                 Else 
                         {
                               Prinf(" not eligible for vote");
                          }
                 Getch( );
 To find out output 
If first condition is true then execute first condition 
Otherwise  by default second condition will be executed 
And printed as it's executing prosess 
  
Flow chart of if else -: 

What is if else if statement  -: 
The use of if else if statement is needed when I have multiple conditions  to execute statements
Syntax : 
                     If ( condition 1)
                            {
                                 Statement 1
                            }
                      Else if ( conditions 2 ) 
                            {
                                 Statement 2    
                            }         
                      Else      
                            {
                                   Statement 3
                             }
                       

In this statment if first condition will be found false then second condition will be execute if it also found false then again execute next condition if last condition is true then last statement will be printed 
 
       Int.  marks; 
                  Clrscr( ) ;
                  Scanf ("%d",& marks) ;
                   If ( marks = 100)
                        { 
                              Printf ("genius") ;
                         }
                    Else if ( marks >=80 && marks                              <100)
                         {
                                Printf (" topper") ;
                          }     
                   Else if ( marks >= 60 && marks                            <=79 )
                          {
                                 Printf (" first  ");
                          }
                      Else 
                          {
                                 Printf ( " Average student")
                           } 
                    Getch( ); 
The output come as per executing of condition  
If first condition will be executed ,the outcome " genius "
 
What is loop -:  loop is used to repeat a block
Of code untill the given condition Is true 

Type -:
                  While loop 
                  For Loop
                  Do while loop
It keep on checking every condition until it get a true condition  
Syntax -: 
                
                  While  ( condition)
                      { 
                           \\ statement ;
                      }
Void main ( ) 
                   Int i = 1;
                   While (i<=10)
                       {
                             Printf ("%d",1);
                              ++ i 
                        }
                        Getch( ) ;
 Output  Printed as 12345678910
       
 Here it get ( i <= 10 ) that is true and print  1
Again it execute the same condition ,the condition is found true print 2 ,it keep on printing until get  i = 10  
 
If give another condition as i >= 10
Here condition found fals while i = 1 

Do while loop -: The do while construct consists of a process symbol and a condition. First, the code within the block is executed, and then the condition is evaluated.     

Syntax  -: 
              Do  
                    {  
                         Statement             
                     }
               While (condition); 

               Int i= 1; 
               Clrscr( ) ;
               Do
                   {
                        Printf ( "%i",i);
                        ++ i ;
                    }
               While (i<=10);
               Getch ( ); 
 
               Do
                    {
                         Printf ("% i", i);
                          ++ i ;
                    }
              While ( i<=0);
              Getch( );
Out put.    0
Here condition is found false, is not executed

For Loop -:  which allows code to be executed repeatedly. Various keywords are used to specify this statement.

                For ( inti = 1; i<=10; i++)
                   {
                       printf ("%", i);     
                    }
                   Get( );
 
                   \\12345678910.
                  Output Printed as
If i give another condition  ( i>=10 )
After executing this statment 
The output come in descending order
                  \\ 10987654321

          Nested loops

A nested loop is a loop inside a loop.
The "inner loop" will be executed one time for each iteration of the "outer loop":

         Clrscr ( );
          For (i=1; i<5; i++)
                {
                        For ( j=1; j<=i ; j++)
                              {
                                   Printf (" * "));
                                }
                         Printf (" \n");
                 }
                 Getch ( );
                                            *
                                            **
                                            ***
                                            ****
    Printed -:                        *****
           
                                           

Since the code block of a loop can include any legal C++ statements, you can place a loop inside of a loop. The inner loop is nested inside the outer loop.

Sample nested loop code

Nested loops are useful when for each pass through the outer loop, you need to repeat some action on the data in the outer loop. For example, you read a file line by line and for each line you must count how many times the word “the” is found. The outer loop would read the lines and the inner loop would search each line for “the” by looping through the words in the line.

Breaking out of a loop

The C++ statement called break provides a way to break out a loop early. The break statement is placed within the body of the loop usually as part of an if statement.

In the example, the loop is set to run a maximum of 50 times but the user can quit the loop at any time by specifying a specific input, q in this case.

sample loop that has a break statement

Should you use break?

The use of break statements is not recommended. We expect the iteration of a loop to be controlled by the true/false statements in the while and do-while and the for loop header sections. Adding a means to suddenly stop the loop outside of the normal approach can make code difficult to understand and debug.

We can rewrite the above code to stop when the user enters q without having to use a break statement such as follows.

sample code using a quit option instead of a break

Using break in a nested loop

In a nested loop, a break statement only stops the loop it is placed in. Therefore, if a break is placed in the inner loop, the outer loop still continues. However, if the break is placed in the outer loop, all of the looping stops.

What Is array -: 

Array is a collection of similar type of data items ina contiguous memory lactation

Note : (1 ) array index always start from zero 
Syntax -: datatype array  name (size)
Int a  ( 5 )  {65 46 68 86 75 }
Type -:  
1D array 
2D array 
Write a program to show the example of 2D &1D array 
        Int main( )
             { 
                 Int a ( 5 ) ={ 65 46 68 86 75 };
                 Int i;
                 For ( i=0; i<5; i++)
                    { 
                         Printf ("%d",a(i));
                      }
              Return 0;
                                  


What is function - : 

Functions are a block of code which take input from the user processe it and produce output 
Note  -: 
Function run only when it is called otherwise will not run
                               Types

  User defined.                         Predefined

 Void add( );.                              Printf ( );
 Int. sum ( );                                scanf ( );
Void main ( );                              puts( ); 

Use defined function
        Return type  function name ( )
                    {
                         || Statement
                     }
         Int. Sum ( int a , int b)
                     {
                           Return  a+b;
                      }
         Int main ( ) 
                      {
                           Int store = sum (10,20);
                           Printf ("%d", store);
                       }
           Getch( ); 

What is storages class -: 

Storage class define the scope and lifetime of variable and function 

Type -:  
(i) -:  auto 
(ii) -: static
(iii) -: Extern 
(iv) -: Register

Storage.  Memory  defaultScope     Lifetim      
Auto          Ram       garbage    with in      Still
                                                    block        block 
                                                                      Is 
                                                                     Active
Static      Ram           0            with in.         Till 
                                                  Block          trmnt
                                                                      P Extern.     Ram          0.            Any where   "  "
Register.  Register   garbage  with in       Still
                                                    block        block 
                                                                      LIs 
                                                                     Active
When the variable is under the block is called
Local variabl
  Int main ( ); 
  Auto int a = 20 ; \\ local
       {  
                If ( 1= i )
               { Auto int b= 20; //local
                      Printf ("%d",a);
                      Printf ("%d", b);
                }
              Return 0;
       }

            
 Output 10 20
                                       

Comments

Popular posts from this blog

📚Gds-Tech 📚 EMS

complete skills