Recent Posts

Showing posts with label Learn Programming. Show all posts
Showing posts with label Learn Programming. Show all posts

Tuesday, 11 December 2018

String function

In the previous post we learn about what is String.we know that string is a collection of two or more characters.In string we can store alphabet, digit and special symbols.

In this post we will learn what are the string functions.

String functions:

1.strcpy ( ):
This function is used to copy the source string into target string.
Syntax: strcpy(target string, source string);
Example:

void main()

{
char stirng1[10],string[20];

clrscr();

printf("type first stirng");

scanf("%s",string1);

strcpy(string2,string1);

printf("second string=%s",string2");

}


Output:
type first string: programming
second string: programming

2.strlen ( ):
This function is used to find out the length of the string.
Syntax: strlen(string name);

3.strcmp ( );
This function is used to compare two strings.if both values are equal then it will return zero.if first string is greater than second string it return value greater than zero.if the value is less than zero then it is case sensitive.
Syntax: strcmp(string1,string2);

4.strcat():
This function appends means add second string at the end of first string.

Syntax: strcat(string1,string2);

5.strrev():
This function reverse contents of the given string and store it again in the same variable.
Syntax: strrev(string);


Friday, 7 December 2018

What is String

String:

  1. String is a collection of two or more characters.
  2. In string we can store alphabets digits and special symbols.
  3. when we declare array of character type then it is called as string.
  4. In C, character type array is used to store a string.

Declaration of String:
The declaration of string is similar like Array.
for declaring string we need to specify its size means maximum of how many characters we have to store in string.

Syntax: char string[size];
Example: char str[20];

Here we declare a string variable str of size 20 means variable 'str' characters.

Initialization of String:
while declaring string we can also initialize some value at the time of declaration.

Syntax: char string[size]="text";
Example: char str[20]="programmingsolution";

Here we declare a string variable 'str' of size 20 and assign programmingsolution to it.

Inputting string:

To input the content in the string two function used as 'scanf()' and 'gets()'.
In 'scanf()' function spaces are not allowed in a string.if we give space then the remaining part will be truncated from string.
In 'gets()' function spaces are allowed in a string.

Syntax:    scanf("%s",string_variable);
                 gets(string_variable);
Example: scanf("%s",str);
                 gets(str); 


Sunday, 4 February 2018

2d array in C

In the previous post we learn about what is array and what is one dimensional array.In this post we will learn what is two dimensional array.

What is Array:

  • Array is a collection of similar type of data type.
  • Array is used to store more than one values of same data type under a single variable name in a continuous memory location.

What is two dimensional Array:

  1. Two dimensional array consist of number of rows and number of columns.
  2. Each row consist of specified number of columns.
  3. For accessing element in two dimensional array we have to provide array name followed by row number and column number.
  4. If we skip the column number then specified row number and first column that is zero index value is accessed.
  5. If we skip both column and row then first row (index zero) and first column (index zero) value is accessed.

How to declare two dimensional Array:              

  1. To declaring two dimensional array we have to write data type followed by followed by array name followed by total number of rows and followed by total number of columns in each row.
  2. Row and column numbers are specified in separate square brackets ([ ]).
Syntax: Data type Array name [row][column];
Example:int num[5][5];


How to initialize two dimensional Array:

  1. We can assign the values to array elements at the time of declaration of array.
  2. Each rows values are enclosed within separate inner parenthesis and two values are separated by comma (,).
Syntax: data type arrayname [row][column]={0th row elements}
                                                                         {1st row elements}
                                                                          .....
                                                                          };
Example: int num [5][5]={{1,2,3,4,5},{2,4,6,7,8},{5,6,7,8,9,}};

   

Wednesday, 24 January 2018

what is one dimensional array


Array is collection of similar type of data type.In the previous post we learn about what is array.
In this post we learn what is one dimensional array

topics we will learn are:
  1. What is one dimensional array.
  2. How to declare one dimensional array.
  3. How to initialize one dimensional array.
Before discuss about one dimensional array we should know what is array and how to declare array.If you don't know you can Read what is array.

What is one dimensional array:
  1. One dimensional array have single row and multiple columns.
  2. For accessing any element in one dimensional array we have to write Array name followed by element number or index number or subscript number.
  3. If we don't specify index number then the first element value will be accessed.


How to declare One dimensional Array:

To declare one dimensional array we have to write data type followed by array name followed by size of array in square bracket([ ]).you can see the below example:

Syntax:     data type array name[size of Array];
Example:  int number[5];


How to initialize One dimensional Array:

We can assign the values to array elements at the time of declaration of array.all values are separated by comma(,).you can see the below example:

Syntax:     data type array name[size of Array]={set of values};
Example:  int number[5]={2,4,6,8,10};

Example:program to input five numbers and print it in reverse order:

#include<stdio.h>
void main()
{
    int a[5],b;
    printf("type 5 numbers");
    for(b=0;b<=4;b++)
    {
        scanf("%d",&a[b]);
    }
    printf("\n in reverse order");
    for(b=4;b>=0;b--)
    {
    printf("\n%d ",a[b]);
    }

}


Output:

type 5 numbers:
2
4
6
8
10

in reverse order:
10
8
6
4
2

Explanation:

  1. When the above program executed first the array 'a'  is declared in memory with size of 5 elements.
  2. To input values loop is placed.
I hope you will understand about one dimensional array.If you like this post please share on social media.

Monday, 22 January 2018

what is array

In the previous post we learn about Difference between compiler and interpreter .In this post we will learn what is array.

What is array:

  1. Array is used to store more than one values of same data type under a single variable name in continuous memory location.
  2. In array each value has a unique index number.
  3. values are start from zero(0).
  4. first value will be stored at index number zero.
  5. The address of first index value is also called as based address.
  6. To access value in array we have to write array name followed by index number in the bracket.
  7. If we don't write index number then by default first element value will be zero is accessed.


Syntax: Data type Array name [size of array];

program for print array elements:

#include <stdio.h>

void main()
{
int a[5]={2,4,6,8,10},b;
for(b=0;b<5;b++)
printf("\n%d",b[a]);
}

Output:
2
4
6
8
10

In the next post we will learn about one dimensional array and two dimensional array.

Wednesday, 17 January 2018

Difference between compiler and interpreter


C is a general purpose programming language.In the previous post we learnt about what is high level language and what is low level language.

The topics we will cover in this post are :
  1. what is interpreter.
  2. what is compiler.
  3. Difference between compiler and interpreter.

What is interpreter:

1.At a time interpreter execute one statement of the high level language.
2.Interpreter is one type of translator used to translate a high level language into its machine language program.
3.A computer can execute only machine language program directly.
4.It takes one statement of the high level language program, translate program, translate it into machine language instructions and then execute the resulting machine language instructions immediately.
5.That is in case of interpreter,the translation and execution processes alternate for each statement encountered in the high level language program.
6.interpreter is slower than compiler.

What is compiler:

1.compiler takes the whole source program written in high level language and translate it into machine language.
2.A computer can execute only machine language program directly.
3.Hence a high level language program must be converted translated into its machine language program before it can be executed on a computer.
4.This translation is done with the help of translator program called compiler.
5.Hence compiler is a translator program that translate a high level language into its machine language program.
6.compiler is faster as compare to interpreter.

Difference between compiler and interpreter:

I hope you will understand What is compiler and interpreter and the difference between compiler and interpreter.If you like this post please share on facebook.

Sunday, 7 January 2018

what is high level language and low level language

In the previous post we learnt about variable and data type.In this post we will learn about computer languages.Today computer can be programmed to understand many different computer languages.In this post we will learn what is High level language and what is Low level language.

we will first discuss what is language.language is means of communication.Language is used to communicate with each other.so when we want to communicate with computer we need a language computer didn't understand our language.computer understand only one language called as machine language or low level language.so in this post we will learn the following points




  1. Low level language
  2. High level language

1.Low level language:

Today computer can be programmed to understand to different programming languages.every computer understand only one language without using a translation language.This language is called machine language of the computer.Machine language is also called as Low level language.The machine language of the computer is written in normally as strings of binary 1's and 0's (zero's).The circuitry of the computer is wired in a manner that it recognizes the machine language instruction immediately,and converts them into electrical signals needed to execute them.

A low level language instruction normally has a two part format as following :

1. OPCODE (operation code) 
2.OPERAND(address/location)

The first part is the operation code that tells the computer what function to perform, and the second part is operand that tells were to find or store the data to be manipulated.Hence each instruction tells the computer what operation to perform and the length and the location of the data fields involved in the operation.Every computer has a set of operation code (or opcode) in the instruction set is made to perform a specific basic operation of function.

2.High level language:

A high level language is a programming language such as C,FORTRAN or PASCAL.that enables a programmer to write program that are more or less independent of a particular type of computer.such language are called as high level language because they are closer to human languages.High level programming languages were designed to overcome the limitation of low level programming language.

They do not require programmers to know anything about the internal structure of the computer on which the high level language programs are executed.

I hope you will understand about high level language and low level language.




Monday, 25 December 2017

Data types in C

     In the previous post we learn about what is Variable in C language.In this post we will learn Data type in C.The data type is a classification of data which tells the compiler or interpreter that how the programmer intends to use the data.The data type define the operation that can be done on data, the meaning of the data.

The basic data type of C are as follows

1.Int :  
          This data type is used to store integer values in the range of -32768 to 32767. It takes 2 bytes               in memory.
Syntax:
int variable_name;

Example:int a;


2.Float:
          This data type is used to store decimal values in the range of 3.4E-38 3.4E+38.It takes 4 bytes               in memory.
Syntax:
float variable_name;

3.Double:
          This data type is used to store decimal values in the range of 1.7E-308 to 1.7E+308.
           It takes 8 bytes in memory.
          This data type is used when accuracy provided by float is not sufficient
Syntax:
double variable_name;

4.Char:
          This data type is used to store characters.It takes one byte in memory to store one character.
Syntax:
char variable_name;

5.Void:
         Void means nothing.This data type is used with function as return data type when function has not return any value to its calling function.

Saturday, 23 December 2017

Variable


If you want to learn programming you must know variable, constant, keywords ,data type and operators in C language.In the previous post we have learn what is constants and type of constants.In this post we will learn Variable.as we know that variable, constant and keyword are the part of the syntax.


  • what is character in C and 
  • what is identifier in C
  • Variable 

C Character set

A character denotes any alphabet, digit or special symbol used to represent information.

Identifier in C

In C programming language identifier is a name given to variable, structure, union, function.The name can contain alphabets digits as shown in above table.

For example
int number;

Here in the above example number is a identifier which denote the variable of integer data type.

Variable:

A value which may change during program execution is called a variable.Variable is nothing but a name to specific location in the memory of computer where different constant are stored.These locations can contain data type as integer,float,character constants.Variable also allows Variable is a container that hold the  value of data type.

Syntax of variable

type variable_list;

Here in the above example type is a data type of c programming language and variable list is a list of variables which are separated by commas.

For example
int    a,b,c;
float  f;
char  c,ch;
double d;

The line a,b,c declare and define the variable a , b and c and which instruct the compiler to create Variable of data type int.
We can initialize the value of Variables at the time of declaration as follows

type variable_name=value;






Friday, 22 December 2017

What is constant in C

In the previous post we have learn about keywords. In this post we will learn about What is Constant they are also part of syntax.

Constants

Constant is a value that doesn't change during program execution.Constants are the fixed values.fixed values are also referred as literals.The alphabets,numbers and special symbols when properly combined they forms constants,variable and keywords.Value is stored in memory at free location.
To declare a constant use const keyword

For example (5*a) 
     In the above example 5 is a constant and 'a' is a variable whose value change during program execution.


Types of constants

Constants are divided into two types as:

1)Primary constants:

     C compiler already know the meaning of Primary constants.In C primary constants are three types as 

1) Integer constant : 

Rules for constructing Integer constants.
1) It should not have a decimal point.
2) An integer constant should have one digit.
3) It can be positive or negative.
4) If no sign precedes as integer constant it is suppose to be positive.
5) No commas or blanks are allowed within an integer constant.
6) The integer constant allowable range is -32768  to +32767.

2) Real constant :
Rules for constructing Real constants
Real constants are also called as floating point constants.The real constants should be written in two forms as Fractional form and Exponential form.

Following rules should be observed where as constructing real constants expressed in fractional form.
It should have a decimal point.
A Real constant should have one digit.
It can be positive or negative
Default sign is positive.
No commas or blanks are allowed within a Real constant
Example :  
+15.54
 29.0
-321.58

            The exponential type representation of real constants is typically used if the value of the constant is too small or too large.It but doesn't limit us in any way from using exponential form of representation for other real constants.

In exponential type of representation,the real constant is represented two parts.The part appearing before 'e' is called mantissa, whereas the part following 'e' is called exponent.   
  • Character constant 

2)Secondary constants

The definition of secondary constants is defined by the programmer.







Thursday, 21 December 2017

what is keyword in C

 C is a programming language which is used for general purpose.About C language we have learnt in previous post C programming language and history and Overview of C. In this post you will learn about keywords in C programming that are part of syntax.

C Keywords

          keywords are the words which means has been already explained to C compiler program.We cannot used keywords as variable names as a  result of if we try to do then the meaning of the keyword will be changed, which is not allowed by the compiler program.the keywords are also called as 'Reserved words'.

There are only 32 keywords available in C.
Keywords cannot be used as variable names.
Keywords cannot used as constant name.
Keywords cannot used as identifier.

For example 

int number;

Here int is a keyword and number is a variable

Below is the list of keywords in C




for example you can see below how union keyword is used



Wednesday, 20 December 2017

History and overview of C language

History of C language

            By 1960  a number of computer languages had come into existence each one is designed for specific purpose.for example FORTAN is use for engineering and scientific applications and COBOL is used for commercial applications and then.At this stage people are thinking rather than learning such a lot of languages why not use any one language which can perform all applications.Ritchie main acheivement is lost generality of BCPL and B, and still keeping it powerful.C's compactness and coherence is mainly due to the fact that it's one man language




Overview of C language

                 C is a object oriented programming language which is developed by Dennis Rirchie in 1972 at the Bell Laboratoried.It is use for develop unix operating system.C is also called mother of all programing languages.This language is used for develop system software.It is widely used language.It can be compiled on different platforms.


Sunday, 17 December 2017

C programming language

C programming language:what is C programming language:


C is a Computer Programming language developed at AT & T's Bell Laboratories,USA in 1972 by Dennis Ritchie. C is a high level and general purpose programming language that is developing for firmware or portable applications. C is developed for developing the UNIX Operating system C began to replace the popular familiar languages of that time like PL/I, ALGOL, etc. Without any advertisement C is very popular and spread, so as a result its users grow fastly.Dennis Ritchie was surprised when he seems many programmers often using C language instead of any other language like FORTRAN or PL/I, or the newer languages like PASCAL,APL.

If you want to Learn programming C is the basic concept of every programming language. C become so popular because it is reliable,easy to use and simple.C is a structured oriented Programming language.At that time dozen of languages available in which PASCAL gets the prize of purity. C was not designed to win prizes,it is designed to be friendly.This language is used for develop system software and Operating system.Therefore a few programmers who begin programming using PASCAL complete their programming with C.

C is also called as mother of all programming languages.All other computer programming languages is basically derived from C  programming language concept.Basically C is the collection of constant, variables and  keywords.

Followers

Popular Posts

Categories

social media

Text Widget

Powered by Blogger.

About Me

My name is junaid khan and i am a full time blogger and author of a blog tutorial called tutorialpointsolution.

String function

In the previous post we learn about what is String .we know that string is a collection of two or more characters.In string we can store al...

Search This Blog

Technology

Adbox

Recent Post

Breaking

Recent In Internet

Comments

Facebook

Pages

Comments

Pages

Recent

Pages

Technology