Friday, 11 September 2020

Variables in C

What is variables:-

variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.

Types of Variables in C

There are many types of variables in c:

(1) local variable

(2) global variable

(3) static variable

(4) automatic variable

(5) external variable


(1) local variable

Those variables that declared inside a block or function is known as local variable.it can be used only in the block where it is declared.


For Example-

  1. Void main ()
  2.                    {
  3.                     int p,q; //local variable
  4.                    }  

(2) global variable     

Those variables that declared in the declaration before the main function block know as global variable.

Global variables can be used throughout the program.


For Example-   

  1. int x,y; //global variable
  2.          void main ()
  3.          {
  4.           ..........................
  5.          }   

 (3) static variable       

static int variable remains in memory while the program is running. A normal or auto variable is destroyed when a function call where the variable was declared is over. ... 4) In Cstatic variables can only be initialized using constant literals. For example, following program fails in compilation.   


For Example-

  1. int fun ()
  2. {
  3.    static int count = 0;
  4.    count ++;
  5.    return count ;
  6. }
  7. int main ()
  8. {
  9.    printf ("%d",fun());
  10.    printf ("%d",fun());
  11.    return 0;
  12. }

(4) automatic variable 

The variables which are declared inside a block are known as automatic or local variables; these variables allocates memory automatically upon entry to that block and free the occupied memory upon exit from that block. Here, both variables a and b are automatic variables


For Example-

  1. void ecodepoint ()
  2. {           int x;
  3.              float y;
  4.              char z;
  5. }
  6. int main()
  7. {           int a,b;
  8.              ecodepoint ();
  9.              return 0;
  10. } 

(5) external variable 

External variables are also known as global variables. These variables are defined outside the function. These variables are available globally throughout the function execution. The value of global variables can be modified by the functions. “extern” keyword is used to declare and define the external variables.  


For Example-

  1. extern int x = 32;
  2. int b = 8;
  3. int main()
  4. {     auto int a = 28;
  5.        extern int b;
  6.        printf ("The valu of auto variable : %d\n",a);
  7.        printf ("The valu of extern variable x and b : %d,%d\n",x,b);
  8.        x = 15;
  9.        printf ("The value of modified extern variable x : %d\n",x);
  10.        return 0;
  11. }


Monday, 7 September 2020

Keywords in c

Keywords in c 

There are 32 Reserve words/keywords  in c programming language

 

A list of 32 keywords in the c language is given below:

auto

 static

extern

register

int

long

float

double

char

void

signed

unsigned

for

do

while

if

else

switch

case

break

continue

default

goto

struct

union

return

Size of

type def

volatile

short

const

enum

 

 

Thursday, 3 September 2020

Use of Printf and Scanf

Use of Printf and Scanf

Use of ''printf" and ''scanf" function with all formating facilities :

In c programming language, "printf" and "scanf" are inbuilt  library function.

These functions are declared and defined in the header file ' ' stdio.h".


Printf

It is used to print the output on to the screen

We cab use printf() function with different format specifier,Following are some of them:-

(1)    %d is used to display the valu of an integer variable.

(2)    %c is used to display chracter.

(3)    %f is used for float variable.

(4)    %s for string variable.

(5)    %if for double.

(6)    %x for hexadecimal variable.

(7)     \n to generate a newline.


scanf :-

It is used to read different type of input from keyboard.

we can use scanf () function with different format specifier.

Following we some of them:-

(1)     %d - the value entered is received as an integer.

(2)     %s - the value entered is received as an string.


program to print sum of  two numbers

Let's see a simple example:-

  1. #include<stdio.h> 
  2. #include<conio.h>   
  3. int main()
  4. {    
  5. int x=0,y=0,result=0;  
  6.   
  7. printf("enter first number:");  
  8. scanf("%d",&x);  
  9. printf("enter second number:");  
  10. scanf("%d",&y);  
  11.   
  12. result=x+y;  
  13. printf("sum of two numbers:%d ",result);  
  14.   
  15. getch();  
  16. }    
enter first number:3                                                                                                          
enter second number:5                                                                                                         
sum of two numbers:8                                                                                                          
                                                                                                                              
...Program finished with exit code 0                                                                                          
Press ENTER to exit console.    






 

First c program

 first c program

Before starting the abcd of C language, you need to learn how to write, compile and run the first c program.

To write the first c program, open the C console and write the following code:


  1. #include <stdio.h> 
  2. #include <conio.h>   
  3. int main()
  4. {    
  5. printf("Hello ecodepoint");    
  6. return 0;   
  7. }  

#include is the first word of any C program

#include <stdio.h> includes the standard input output library functions.

int main() The main() function is the entry point of every program in c language.

return 0 The return 0 statement, returns execution status to the OS. The 0 value is used for successful execution and 1 for unsuccessful execution.

Best compile and run the c program.


Hello ecodepoint                                                                                                              
                                                                                                                              
...Program finished with exit code 0                                                                                          
Press ENTER to exit console.                                                                                                  
                                      


Tuesday, 1 September 2020

How to install C (Best software and compiler)

How to install C  (Top software and run the c or c++ language )

1. There are many compilers available for c and c++. You need to download any one. Here, we are going to use Turbo C++. It will work for both C and C++. To install the Turbo C software, you need to follow following steps.

  1. Download Turbo C++
  2. Create turboc directory inside c drive and extract the tc3.zip inside c:\turboc
  3. Double click on install.exe file
  4. Click on the tc application file located inside c:\TC\BIN to write the c program
2. How to install codeblocks

       
  1.download

     Goto http://www.codeblocks.org/downloads. Click "Download the binary release". Select your operating        platform (e.g., Windows 2000/XP/Vista/7). Download the installer with GCC Compiler,                                     e.g., codeblocks- 13.12mingw-setup.exe (98 MB) (which includes MinGW's GNU GCC compiler and           GNU GDB debugger).

    2: Install

     Run the downloaded installer. Accept the default options.

   Verify the Compiler's and Debugger's Path: (For CodeBlocks 13.12 For Windows) Goto "Settings"          menu ⇒ "Compiler..." ⇒ In "Selected Compiler", choose "GNU GCC Compiler" ⇒ Select tab "Toolchain                     Executables" ⇒ Check the "Compiler's Installation Directory". It shall be set to the "MinGW" sub-directory of the  CodeBlocks installation directory, for example, suppose that CodeBlocks is installed in "c:\Program Files\codeblocks", set it to "c:\Program Files\codeblocks\MinGW".

Similarly, check the debugger's path. Goto "Settings" menu ⇒ "Debugger..." ⇒ Expand "GDB/CDB debugger" ⇒ Select "Default" ⇒ In "Executable path", provide the full-path name of "gdb.exe", for example, "c:\Program Files\codeblocks\MinGW\bin\gdb.exe". 

Debugging C/C++ program in codeblocks

  1. Step 0: Write a C++ Program. ...
  2. Step 1: Set an Initial Breakpoint. ...
  3. Step 2: Start Debugging. ...
  4. Step 3: Single-Step and Watch the Variables and Outputs. ...
  5. Step 4: Breakpoint, Run-To-Cursor, Continue and Stop.

3. online compiler and debugger for C/C++

   click to Link write now-


Features of c language

      Features of c language

      C is the widely used language. It provides a lot of features that are given below.

  1. Simple
  2. Machine Independent or Portable
  3. Mid-level programming language
  4. structured programming language
  5. Rich Library
  6. Memory Management
  7. Fast Speed
  8. Pointers
  9. Recursion
  10. Procedural Language
  11. Fast and Efficient
  12. Modularity
  13. Statically Type
  14. General Purpose Language
  15. Rich set of built in Operators
  16. Libraries with rich Functions
  17. Middle Level Language
  18. Portability
  19. Easy to Extend
  20. Extensible
1. Simple- C is a simple language in the sense that it provides structured approach (to break the problem into parts), rich set of library functionsdata types etc.

_________________________________________________________

2. Machine Independent or portable- Unlike assembly language, c programs can be executed on many machines with a little bit or no change. But it is not platform-independent.

______________________________________________

3. Mid-Level programming language- C is also used to do low-level programming. It is used to develop system applications such as kernel, driver etc. It also supports the feature of high level language. That is why it is known as mid-level language.

______________________________________________

4. structured programming language- C is a structured programming language in the sense that we can break the program into parts using functions. So, it is easy to understand and modify.

______________________________________________

5. Rich Library- provides a lot of inbuilt functions that make the development fast.

______________________________________________

6. Memory Management- It supports the feature of dynamic memory allocation. In C language, we can free the allocated memory at any time by calling the free() function.

______________________________________________

7. Fast Speed- The compilation and execution time of C language is fast.

______________________________________________

8. Pointers- C provides the feature of pointers. We can directly interact with the memory by using the pointers. We can use pointers for memory, structures, functions, array etc.

______________________________________________

9. Recursion- In c, we can call the function within the function. It provides code reusability for every function.

______________________________________________

10. Procedural Language- In a procedural language like C step by step predefined instructions are carried out. C program may contain more than one function to perform a particular task. New people to programming will think that this is the only way of a particular programming language works. There are other programming paradigms as well in the programming world. Most of the commonly used paradigm is an object-oriented programming language.

___________________________________________________________

11. Fast and Efficient-  Newer languages like java, python offer more features than c programming language but due to additional processing in these languages, their performance rate gets down effectively. C programming language as the been middle-level language provides programmers access to direct manipulation with the computer hardware but higher-level languages do not allow this. That’s one of the reasons C language is considered as the first choice to start learning programming languages. It’s fast because statically typed languages are faster than dynamically typed languages.

___________________________________________________________

12. Modularity-  The concept of storing of C programming language code in the form of libraries for further future uses is known as modularity. This programming language van does a very little on its own most of its power is held by its libraries. C language has it’s own library to solve common problems like in this we can use a particular function by using a header file stored in its library.

___________________________________________________________

13. Statically Type- C programming language is a statically typed language. Meaning the type of variable is checked at the time of compilation but not at run time. Means each time a programmer type a program they have to mention the type of variables used.

___________________________________________________________

14. General purpose language-  From system programming to photo editing software, C programming language is used in various applications. Some of the common applications where it’s used are as follows:
_____________________________________________________

15. Rich set of built in operatorsIt is a diversified language with a rich set of built-in operators which are used in writing complex or simplified C programs.

__________________________________________________________

16. Libraries with rich functions- Robust libraries and functions in C help even a beginner coder to code with ease.

__________________________________________________________

17. Middle Level Language- As it is a middle-level language so it has the combined form of both capabilities of assembly language and features of the high level language.

__________________________________________________________

18. Portability- C language is lavishly portable as programs which are written in C language can run and compile on any system with either none or small changes.

__________________________________________________________

19. Easy to Extend- Programs written in C language can be extended means when a program is already written in it then some more features and operations can be added into it.

__________________________________________________________

20. Extensible- C language is extensible because it can easily adopt new features.

________________________________________________________




Histroy of c language

 what is c 

The base or father of programming languages is 'ALGOL.' It was first introduced in 1960. 'ALGOL' was used on a large basis in European countries. 'ALGOL' introduced the concept of structured programming to the developer community. In 1967, a new computer programming language was announced called as 'BCPL' which stands for Basic Combined Programming Language. BCPL was designed and developed by Martin Richards, especially for writing system software. This was the era of programming languages. Just after three years, in 1970 a new programming language called 'B' was introduced by Ken Thompson that contained multiple features of 'BCPL.' This programming language was created using UNIX operating system at AT&T and Bell Laboratories. Both the 'BCPL' and 'B' were system programming languages.

In 1972, a great computer scientist Dennis Ritchie created a new programming language called 'C' at the Bell Laboratories for use with the Unix operating system,

                     


                   

Variables in C

What is variables:- A  variable  is nothing but a name given to a storage area that our programs can manipulate. Each  variable in C  has a ...