helllo sir ,
what is the main use of the pointer ,array ,and the
structure with the example of a programe

Answer Posted / vignesh1988i

POINTERS :
pointers are derived data types which is used to store an address of a variable of the similar data type in which the pointer have been declared. it is denoted as '*', it is called dereference operator.
for eg:
int i=90, *pointer;
according to the above definition,
pointer= &i // assiginig the address of i to integer pointer which points to variable 'i'.
printf("%d`n",*pointer); // prints the value of i

integer ptr can hold only integer addresses , char ptr can hold only character variable address etc.

but void pointers can hold any data type at that instance of time , that pointer must be type casted at that time to point to which data typed variable.

ARRAY :
arrays are called as a linear data structure which allocates continous memory locations of SIMILAR DATA TYPES.
DECLARATION :
data type array_name[an integer]; // only integer value can be used within the subscript ([ ]).

INITILIZATION :

int first[]='1','2','3';
here no error will occur at the time of INITILIZATION ,ie giving the values when we declare an array....

but this is a wrong ones :

int first[]; //error statement

an important point to remember :

ARRAYS ARE RELATED TO POINTER S AND VICE VERSA.
whenever we refer to an array , first thing we have to remember is the BASE ADDRESS of an array....... ie the very first location ie. &array[0] - refers to the base address ,

so when we write array[0] or array[i] where i=0,1,2,3,......n ; it is implicitily writtern as *(array+0) or *(array+i) .

ARRAYS can be classified as ONE DIMENSION or MULTI DIMENSIONS.

for eg:

int logic[50][10];

STRUCTURES :

structures are called user defined data types which can hold a series of same or different data types of data at one go....
DIFFRENCE between array and a structure is :
1) array allocates ONLY continous memory locations of SAME DATA TYPE.......
but STRUCTURE allocates continous locations or it splits up the memory locations implicitily without leting it out to the user.

2) strutures are not related to pointers
but arrays are related

3) when arrays are declared it can be inililized but
structures cannot be.
this point will be more clear while you see the below coding:

DECLARATION :
struct vignesh
{
char name[20];
int roll_no;
float avg;
}a1;
here are three things have to be remembered :
1) vignesh REFERS to the structure name
2)The items inside {.... } refers to the DATA MEMBERS to a structure vignesh
3)a1 refers to the STRUCTURE variable.....
the speciality here is in this a1 3 datas of different data types can be stored ie. char name[20] , int roll_no , float avg .......
to refer to the members of the structures we must access those with '.' operater.

printf("%s n% %d`n %f`n",a1.name,a1.i,a1.avg);



I CAN SAY MORE ABOUT THESE THREE THINGS BUT I THINK THIS SMALL INTRODUCTION WILL BE ENOUGH TO MAKE YOU CONCEPTUALLY CLEAR......


thank u

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the Purpose of 'extern' keyword in a function declaration?

874


Describe the difference between = and == symbols in c programming?

1039


What is union and structure?

809


How many data structures are there in c?

854


Is c procedural or functional?

806


What will be the outcome of the following conditional statement if the value of variable s is 10?

1071


Write a program that accept anumber in words

1501


What is the advantage of an array over individual variables?

1012


Is array a primitive data type in c?

818


Write a function expand(s1,s2) that expands shorthand notations like a-z in the string s1 into the equivalent complete list abc...xyz in s2 . Allow for letters of either case and digits, and be prepared to handle cases like a-b-c and a-z0-9 and -a-z. z-a:zyx......ba -1-6-:-123456- 1-9-1:123456789987654321 a-R-L:a-R...L a-b-c:abbc

5381


main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }

1166


Explain pointers in c programming?

888


Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?

1041


write a c programming using command line argument,demonstrate set operation(eg;union,intersection,difference) example output is c:>setop 12 34 45 1 union 34 42 66 c:>setop 12 34 1 42 66 c:>setop 12 34 diff 12 56 67 78 setop 12 34

1885


what is the different bitween abap and abap-hr?

1956