Pointer

1. POINTERS:

pointers are the variable it stores the address of another variable, a pointer variable is given as *variable.

1.1 Declare int, char variable and 2 pointer variable for respected data types,assign the address. print the value of&a,aptr,*aptr,&aptr,&b, bptr,*bptr,&bptr.

#include<stdio.h>

int main()

{

int a;

char b;

int *aptr;//pointer variable for integer

char *bptr;//pointer variable for character

a=10;//declaration of integer a

b=’e’;//declaration of integer b

aptr=&a;//pointer variable stores the address of a variable

bptr=&b;

printf(“%ld\n”,sizeof(bptr));//to print the memory size

printf(“%d %p %p %p \n”,*aptr,&a,aptr,&aptr);//%p for printing

the address(hexadecimal)

printf(“%c %p %p %p \n”,*bptr,&b,bptr,&bptr);

}

1.2, Declare an array of size (5) assign its address to an integer pointer using the pointer, initialize array and pointer array.

#include<stdio.h>

int main()

{

int a[5]={1,2,3,4,5},*p,i;//array initialization along with

initialization of pointer variable

for(i=0;i<5;i++)//loop for storing address address of each

element of the array

{

p=&a[i];

printf(“%d %p\n”,*p,p);//for printing array values and the

address of each element of the array

p++;

}

}

1.3 Print your name using pointer. print the address of each element of your name.

#include<stdio.h>
void str(char a[],int size);
int main()
{
char a[8]={“priyanka”};//character array for storing name
str(a,8);//function call
}
void str(char a[],int size)
{
int i;
char *p;//character pointer variable
p=&a[0];//address of first element of the string
printf(“%s\n”,p);//by using address it prints whole string
printf(“%d\n”,sizeof(p));
for(i=0;i<8;i++)//loop for obtaining address of the each element
in the name
{
p=&a[i];
printf(“%c %p\n”,*p,p);
p++;//next location
}
}

1.4 Addition,subtraction,multiplication and division of two numbers using pointers.

#include<stdio.h>
int add(int a,int b);//prototypes of add,sub,mul,div
int sub(int a,int b);
int mull(int a,int b);
float divi(int a,int b);
int main()
{
int a,b,sum,diff,mul;
float div;
printf(“enter the two numbers:\n”);
scanf(“%d %d”,&a,&b);
sum=add(a,b);//function call for addition
printf(“sum=%d\n”,sum);
diff=sub(a,b);//function call for subtraction
printf(“difference=%d\n”,diff);
mul=mull(a,b);//function call for multiplication

printf(“xtion=%d\n”,mul);

div=divi(a,b);//function call for division
printf(“div=%f\n”,div);
}
int add(int a,int b)//for addition of two given numbers using pointers
{
int *res,*x,*y,c;
x=&a;
y=&b;
c=*x+*y;
res=&c;
return *res;
}
int sub(int a,int b)//for subtraction of two given numbers using
pointers
{
int *res2,*x2,*y2,c;
x2=&a;
y2=&b;
c=*x2-*y2;
res2=&c;
return *res2;
}
int mull(int a,int b)//for multiplication of two given numbers using
pointers
{
int *x3,*y3,*res3,c;
x3=&a;
y3=&b;
c=(*x3)*(*y3);
res3=&c;
return *res3;
}
float divi(int a,int b)//for division of two given numbers using
pointers
{
float *x4,*y4;
float *res4;
x4=&a;
y4=&b;
*res4=*x4/(*y4);
return *res4;
}

1.5 Find the average of 5 given numbers using pointers

#include<stdio.h>
float avg(float a[],int size);//function defination
int main()
{
float a[5],res;
int i;
printf(“enter the 5 numbers to find the average\n”);
for(i=0;i<5;i++)
{
scanf(“%f”,&a[i]);//user input of five numbers
}
res=avg(a,5);//function call
printf(“average=%f”,res);//printing result
}
float avg(float a[],int size)
{
float *p,*res,avg1,c=0;//declaration of pointer variable
int i;
for(i=0;i<size;i++)
{
p=&a[i];
c=c+*p;//for finding the sum of five entered numbers
p++;
}
res=&c;
avg1=*res/5;//for finding average
return avg1;
}

1.6 Swap the two given numbers using pointers

#include<stdio.h>
void swap(int *x,int *y);
int main()
{
int a,b;
printf(“enter the two numbers a and b\n”);
scanf(“%d %d”,&a,&b);//user input of two numbers
printf(“before swapping a=%d b=%d”,a,b);
swap(&a,&b);//we pass address of the variables to the function
arguments
printf(“\nafter swapping a=%d b=%d”,a,b);//printing result after
swapping
}
void swap(int *x,int *y)
{
int t;// using temporary variable we swapping the two variables
using pointers
t=*x;
*x=*y;
*y=t;
}

1.7 Write a program to take your name as input save into another array using the pointer

#include<stdio.h>
void name(char a[],int size);
int main()
{
char a[8];// declaration of input array
printf(“enter the name\n”);
scanf(“%s”,a);//user input of our name
name(a,8);//function call of array name and size
}
void name(char a[],int size)
{
char c[8],i,*p;//declaration of the new array and pointer
variable
for(i=0;i<8;i++)
{
p=&a[i];//storing the address of the each elements of the
input array
printf(“%c”,*p);//dereferencing the pointer variable to print the
each element in the array
c[i]=*p;//storing each element into new array c[i] one by
one
p++;
}
printf(“\nthe new c array is\n”);
printf(“%s”,&c[0]);// printing the c array by using string
concept
}

1.8 Find out how many vowels are there in name using pointers

 DESCRIPTION:

1)Give any name as a input to character array as a string.

2)declare the character pointer variable and feed the string address to that variable.

3)compare the given string elements one by one with the five vowels(a,A,e,E,i,I,o,O,u,U),if the elements is equal     to this letters then increment the counter variable(intialize it to zero first.

4)print the counter value as number of vowels found in this string of given name.

MEMORY MAPPING:Input character array(any input)=priyanka

ptr=&name[0](or we can use ptr=name ptr=address of first character of the given array

ptr++=(address of the next character,we keep on incrementing till end of the string(‘\0′)

*ptr=dereferencing value

the address of each character of given input is as follow

p=0xbfa36f2

r=0xbfa36f3

i=0xbfa36f4

y=0xbfa36f5

a=0xbfa36f6

n=0xbfa36f7

k=0xbfa36f8

a=0xbfa36f9

note:this address may be changing for each compilation and different pcs

 

#include<stdio.h>

int main()

{

char name[10],*ptr;//*ptr is a pointer variable

printf(“enter the name\n”);

scanf(“%s”,name);

ptr=&name[0];//for string we need not to add (&)address symbol

int vowel=0;//vowel count in the given name

int consonant=0;//number of consonant in the given name

while(*ptr!=’\0′)//we keep on comparing the each elements in the name till end of the string

{

if(*ptr==’A’||*ptr==’a’||*ptr==’E’||*ptr==’e’||*ptr==’I’||*ptr==’i’||*ptr==’O’||*ptr==’o’||*ptr==’U’||*ptr==’u’)

vowel++;//if condition to check the number of vowels in the given name

else

consonant++;

printf(“%c=%p\n”,*ptr,ptr);//to print the address of each letter

ptr++;//for next location

}

printf(“the number of vowels=%d\n the number of consonant=%d\n”,vowel,consonant);

}

1.9 Write a program to subtract two numbers using the function, pass one argument as integer pointer and another as integer,return the integer pointer to the main function.

#include<stdio.h>

int* sub(int *x,int y);//return type is

int main()

{

int a,b,*d;

printf(“enter the two numbers to find the difference\n”);

scanf(“%d %d”,&a,&b);

d=sub(&a,b);//function call

printf(“the difference value is=%d\n”,*d);//printing the difference value

}

int* sub(int *x,int y)

{

*x=*x-y;//subtraction process

return x;//returning address.

}

1.10 Pass two char array as the size of the same size into a function using a pointer, in the function write a program to compare both arrays and return  0 or 1.if they are the same return 1 and if they are not the same return 0.

 

#include<stdio.h>

int cmp(char *x,char *y);

int main()

{

char array1[10],array2[10];

int p;

printf(“enter the first character array\n”);

scanf(“%s”,array1);

printf(“enter the second character array\n”);

scanf(“%s”,array2);

p=cmp(&array1[0],&array2[0]);//function call where we pass the address of first element of both strings

if(p==1)

printf(“two strings are equal\n”);

else

printf(“two strings are not equal\n”);

}

int cmp(char *x,char *y)//receiving the adress of first elements as a pointers in function

{

while(*x==*y)//to compare 1st elements of the array initially, if it agrees then continue else return 0

{

if(*x==’\0′ || *y==’\0′)//if any one string becomes null then stop running of loop

break;

printf(“%c=%p\n”,*x,x);

x++;//next location address of first array

y++;//next location address of second array

}

if(*x==’\0′ && *y==’\0′)//if both the strings are become null at a time

return 1;

else

return 0;

}

1.11 Declare array of character pointer initialize them and print them.

#include<stdio.h>

int main()

{

char *name[10]=”priyanka”;//character array declaration

printf(“%s”,&name[0]);//or printf(“%s”,&name[0]);/*for

string only first address is required.*/

}

 

 

TWO DIMENSIONAL ARRAY

We have introduced array as if we want to save a hundred values then its difficult to declare variables, so we used array .now if we want hundred such arrays then we can have two-dimensional arrays .so an array of arrays is known as 2d array.

1.1 PROGRAM TO CHECK WHETHER THE TWO(3*3) MATRIXES ARE EQUAL OR NOT

DESCRIPTION:

First we taken the two(3*3) matrixes, afterwards we need to check that all elements inside the two matrixes are equal or not in both matrixes with respect toposition wise also, if all elements with respect to position in two matrixes are equal then prints both matrices are EQUAL otherwise prints both matrixes are not equal.
#include<stdio.h>
int main()
{
int matrix1[3][3],matrix2[3][3],i,j,count=0;
printf(“enter the elements of first 3*3 matrix\n”);
for(i=0;i<3;i++) //rows
{
for(j=0;j<3;j++)// columns
{
scanf(“%d”,&matrix1[i][j]); //input from the user
}
}
printf(“enter the elements of second 3*3 matrix\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&matrix2[i][j]);
}
}
for(i=0;i<3;i++) //loop for checking whether two matrixes are equal or not
{
for(j=0;j<3;j++)
{
if(matrix1[i][j]!=matrix2[i][j])
{

count++;// increment the count value if the elements are not

equal
}
}
}
if(count==0)
printf(“2 matrixes are equal\n”);
else
printf(“2 matrixes are not equal\n”);
}

1.2 TO PERFORM SCALAR MULTIPLICATON OF(3*3) MATRIX

Description:

Here we can multiply any constant element with the 3*3 matrix(or any other matrix).first user ask the input for matrix along with the constant variable.
#include<stdio.h>//preprocessor directive with header file
int main()
{
int matrix[10][10],i,j,n,constant,row,col,matrix1[10][10];
printf(“enter the number of rows of the array elements\n”);
scanf(“%d”,&row);
printf(“enter the number of columns of the array elements\n”);
scanf(“%d”,&col);
printf(“enter the matrix elements\n”);
for(i=0;i<row;i++)
//for row elements
{
for(j=0;j<col;j++)
//for column elements
{
scanf(“%d”,&matrix[i][j]);
}
}
printf(“enter the constant element to multiplied with the matrix\n”);
scanf(“%d”,&constant);
for(i=0;i<row;i++)
//loop for multiplying a constant with the given matrix
{
for(j=0;j<col;j++)
{
matrix1[i][j]=constant*matrix[i][j];
}
}

printf(“the new matrix is\n”);

for(i=0;i<row;i++)
//loop for printing the multiplied matrix
{
for(j=0;j<col;j++)
{
printf(” %d”,matrix1[i][j]);
}
printf(“\n”);
}
}//end of main function

1.3 TO FIND THE SUM OF EACH ROW AND COLUMN OF A 3*3 MATRIX

DESCRIPTION:

First we have to take(3*3) matrix,then we need to find the sum of each elements of the row1,afterwards sum of each elements of row2 and then row3, similar method is needed to find the sum of each elements of columns also.afterwards print all the sums individually.
#include<stdio.h>
int main()
int matrix[3][3],i,j,sum,row=0,sum1;
printf(“enter the elements of the matrix(3*3)\n”);
for(i=0;i<3;i++)// scanning for rows
{
for(j=0;j<3;j++)// scanning for columns
{
scanf(“%d”,&matrix[i][j]);
}
}
for(i=0;i<3;i++)//loop for finding the sum of each rows and columns
{
sum=0;
sum1=0;
for(j=0;j<3;j++)
{
sum=sum+matrix[i][j];//sum is sum of each rows
sum1=sum1+matrix[j][i];//sum1 is sum of each columns
}
printf(“sum of row%d=%d\n”,row,sum);//printing sum of each rows value
printf(“sum of column%d=%d\n”,row,sum1);//printing sum of each
column value
row++;

}

}

1.4 MULTIPLICATION OF TWO 3*3 MATRIX

DESCRIPTION:

First we take the two 3*3 matrixes(or any), afterwards we need to check the rows of the first matrix is equal to the columns of the second matrix, if it is satisified then only you to process for further steps otherwise print no multiplication is possible,if it is satisified then only multiply 2 matrix.
#include<stdio.h>
int main()
{
int matrix1[3][3],matrix2[3][3],matrix3[3][3],row1,col1,row2,col2,i,j,k,mul;
printf(“enter the number of rows of the first matrix\n”);
scanf(“%d”,&row1);
printf(“enter the columns of the first matrix\n”);
scanf(“%d”,&col1);
printf(“enter the elements of the first matrix\n”);
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
scanf(“%d”,&matrix1[i][j]);
}
}
printf(“enter the number of rows of second matrix\n”);
scanf(“%d”,&row2);
printf(“enter the number of columns of second matrix\n”);
scanf(“%d”,&col2);
if(row1!=col2) //if rows of the 1st matrix not equal to second matrix exit program
otherwise continue
printf(“multiplication not possible\n”);
else
{
printf(“enter the elements of the second matrix\n”);
for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
{
scanf(“%d”,&matrix2[i][j]);
}

}

printf(“multiplication of two matrix is\n”);
for(i=0;i<row1;i++) // matrix multiplication takes place
{
for(j=0;j<col2;j++)
{
mul=0;
for(k=0;k<col1;k++)
{
mul=mul+matrix1[i][k]*matrix2[k][j];
}
printf(” %d”,mul);
}
printf(“\n”);
}
}
}

1.5 PROGRAM TO STORE 10 NAME INTO 2D ARRAY AND PRINT THEM

DESCRIPTION:

We declare a 2 dimensional character array of required size,afterwards we need to store names, and print them.
#include<stdio.h>
int main()
{
char names[20][20];
int row,col,i,j;
printf(“enter the rows and columns of the 2d array\n”);
scanf(“%d %d”,&row,&col);
printf(“enter the names you want to print\n”);
for(i=0;i<row;i++)
{
scanf(“%s”,&names[i][0]);//user input to store names
}
for(i=0;i<row;i++)
{
printf(“%s\n”,&names[i][0]);//printing the names
}
}

1.6 PROGRAM TO SWAP THE TWO ARRAYS

DESCRIPTION:

To swap two strings in c programming we want to ask user to enter two strings and then make a temporory variable of same type and then place elements of string 1 in temp and and elements of string 2 in 1 and then temp in string 2.
#include<stdio.h>
int main()
{
char array1[10],array2[10],temp[10]=”\0″;
int len1=0,len2=0,i,j;
printf(“enter the elements of the first array\n”);
scanf(“%s”,array1);
printf(“enter the elements of the second array\n”);
scanf(“%s”,array2);
while(array1[len1]!=’\0′)//loop for calculating the length of the first array
{
len1++;
}
printf(“the length of the first array is %d\n”,len1);
while(array2[len2]!=’\0′)//loop for calacuating the length of the second array
{
len2++;
}
printf(“the length of the second array is %d\n”,len2);
for(i=0;i<len1;i++)//using temporary variable we swap the 2 given arrays and
print after the swapping process
{
temp[i]=array1[i];
}
for(i=0;i<len2;i++)
{
array1[i]=array2[i];
}
for(i=0;i<len1;i++)
{
array2[i]=temp[i];
}
for(i=0;i<len2;i++)
{
printf(“%c”,array1[i]);
}
printf(“\n”);
for(j=0;j<len1;j++)
{
printf(“%c”,array2[j]);
}
}

1.7 PROGRAM TO CHECK WHETHER THE GIVEN STRING IS PALINDROME OR NOT

DESCRIPTION:

A string is palindrome if the reverse of that string is equal to original string.firstly we need to declare a character array of some size, after we need to obtain input string from the user, and take another array and copy the reversing order of first string and comapare the both strings if it is equal print as the given string is palindrome else print the given string is not an palindrome.
#include<stdio.h>
#include<string.h>
int main()
{
char str[10],rev[10]=”\0″;
int length=0,i,j;
printf(“enter the string\n”);
scanf(“%s”,str);
while(str[length]!=’\0′)//while loop to find the length of the string till the element become
{
length++;
}
printf(“length of the string is=%d\n”,length);
for(i=length-1,j=0;i>=0,j<length;i–,j++)/*for loop for reversing a original string and store it in
another character
array*/
{
rev[i]=str[j];
}
for(i=0;i<length;i++)//comparing original string with the reversing string
{
if(rev[i]==str[i])
j=1;
else
j=0;
}
if(j==1)
printf(“palindrome\n”);
else
printf(“not an palindrome\n”);
}

1.8 PROGRAM TO INTERCHANGING THE DIGONALS OF MATRIX

DESCRIPTION:

Firstly we take the matrix (only square matrix),afterwards we need to interchange the left diagonal elements towards right and viceversa and print the result of interchanging the diagonal elements.
#include<stdio.h>
int main()
{
int a[10][10],row,column,i,j,temp;
printf(“enter the number of rows and columns of the matrix\n”);
scanf(“%d %d”,&row,&column);
printf(“enter the elements of the matrix\n”);
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
scanf(“%d”,&a[i][j]);
}
}
for(i=0;i<row;i++)
{
temp=a[i][i];
a[i][i]=a[i][row-i-1];
a[i][row-i-1]=temp;
}
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
printf(” %d”,a[i][j]);
}
printf(“\n”);
}
}

1.9 WRITE A PROGRAM TO PRINT UPPER TRIANGULAR MATRIX

DESCRIPTION:

we have to take one square matrix and print the upper triangular matrix only remaining the term should be zero or empty.
#include<stdio.h>
int main()
{
int matrix[3][3],row,column;
printf(“enter the (3*3) matrix elements\n”);
for(row=0;row<3;row++)
{
for(column=0;column<3;column++)
{
scanf(“%d”,&matrix[row][column]);
}
}
for(row=0;row<3;row++)
{
for(column=0;column<3;column++)
{
if(column>=row)
{
matrix[row][column]=matrix[row][column];//assign the elements as it is if column is
greater or equal,else it is 0
}
else
{
matrix[row][column]=0;
}
}
}
for(row=0;row<3;row++)
{
for(column=0;column<3;column++)
{
printf(” %d”,matrix[row][column]);
}
printf(“\n”);
}
}

1.1 PROGRAM TO READ 10 NAMES INTO 2D ARRAY AND SORT THEM BASED ON THE FIRST ELEMENT IN ALPHABETICAL ORDER

DESCRIPTION:

Firstly we can take some of names from the user input and then we have to compare first letter of each names and then use swapping technique if one letter greater than other,after completing the sorting technique, we will get strings of names in alphabetical order.
#include<stdio.h>
#include<string.h>
int main()
{
char names[10][10],temp;
int i,j,k;
printf(“enter the names(10):\n”);
for(i=0;i<10;i++)
{
scanf(“%s”,&names[i][0]);
}
for(k=0;k<10;k++)//loop for swapping until all the elements will be sorting in alphabetical order
{
for(i=0;i<10-1;i++)//swapping all the elements in the array only one time
{
if(names[i][0]>names[i+1][0])/*comparing the first letters of the names and if
greater swap else don’t swap*/
{
for(j=0;j<10;j++)
{
temp=names[i][j];
names[i][j]=names[i+1][j];//swapping
names[i+1][j]=temp;
}
}
}
}
printf(“\n”);
printf(“string name in alphabetical order\n”);//after the swapping technique print the sorted
names
for(i=0;i<10;i++)
{
printf(“%s\n”,&names[i][0]);
}
}

What Programming Language is Used for Embedded Systems?

programming language is used for embedded systems - PTInstitute

Embedded system is a combination of both hardware and software. Embedded system is growing very fast. To program any embedded device mainly c programming is used.
To work in the embedded field, c programming is enough to manage all embedded devices. C programming is high-level programming, which is used to control the device. All the controllers like microcontroller 8051, 8052, PIC controller, STM32 all can be programmed by c programming.
We can use different programming languages for an embedded system like assembly language, some scripting languages Perl, and python. Try PTInstitute for embedded courses in Bangalore.
The B programming language was created to complete these tasks with a very less number of lines code, but it did not have data types or structures. C was then created which implemented features missing in B. C then became the standard the programming language in the UNIX systems.
C was created in the early 70s by Dennis Ritchie as a high-level programming language in UNIX operating systems. At that time, the Assembly language was mainly used, assembly language required many lines of code to accomplish a simple task. If you are good at c programming you can learn any programming language easily. C programming involves functions, arrays, pointer, and data structure. Most of the embedded system devices are developed using the c programming language. If you are looking for c programming teaching institutes. you can search for best embedded system training institute in Google.
Hardware Description Languages are used a lot in FPGAs and parallel programming applications. They are quite different from many other types of languages in that they are frequently used based on hardware, hence “hardware description”.
Verilog was invented in the early 80s as one of the first HDLs, used primarily in the modeling of electronic systems. The language name is a shortened version of “Verification of LOGIC”. The program is based on a hierarchy of modules to be able to describe a system. Verilog may be easier to learn if you already have experience with programming in C.
Verilog was invented in the early 80s as one of the first HDLs, used primarily in the modeling of electronic systems. The language name is a shortened version of “Verification of LOGIC”. The program is based on a hierarchy of modules to be able to describe a system. Verilog may be easier to learn if you already have experience with programming in C.

Ada Programming Language

Ada is statically typed, essential, and structured programming language, Ada is a mainly extended from Pascal it’s a high-level object-oriented computer programming language. Ada is mainly targeted at real-time systems and embedded systems. Some important features of Ada programming language are we can check the code during the run time and we can do parallel processing, it includes generics, exception handling and dynamic dispatch.
Ada is mainly designed for the development of very large software systems. Packages of Ada can be compiled individually. Ada package specifications can also be compiled individually without the implementation to check for reliability. This help to detect problems early mainly during the design phase, as before implementation starts.

Python Programming Language:

Python is high level, the interpreted general-purpose programming language it is developed by Guido van Rossum first it was released in 1991.
Python is garbage collected and dynamically typed language. Python supports multi programming paradigms including object-oriented, procedural and functional programming as well. You can search for well-embedded training institutes in Bangalore.
Python is frequently described as batteries included language because of its comprehensive standard library files.
Python programming language is used in an embedded system as well, to design an embedded system like in IoT python programming is used.
We at Professional Training Institute give practical oriented training on the embedded system, c programming language, python.

En-Query

Your Name*
Subject*
Phone Number*
Email Address*

Message*