ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
helllo sir ,
 what is the main use of the pointer ,array ,and the 
structure with the example of a programe
 Question Submitted By :: Pawan Kumar Singh
I also faced this Question!!     Rank Answer Posted By  
 
  Re: helllo sir , what is the main use of the pointer ,array ,and the structure with the example of a programe
Answer
# 1
With the help of pointer we can access a variable 
address.with that we can change the value of the 
variable.for eg: 

main()
{
 int a = 10;
 int *x;
 
 x = &a;
 
 printf("a = %d\n",a);
 *x = 978;
 printf("a = %d\n");
}

now the value of the a is 978.

if we pass a pointer to a variable to a function then the 
value of that variable will be chageed if we change it in 
that function.
for eg: 

main()
{
  int b = 87;
  int *x;
  x = &b;
  fun(x);
  printf("b = %d\n");
}

fun(int *x)
{
  *x = 879;
}

here the value of the b will be 879.

Array : Array is a collection of variable of similar types. 
i.e. it can b an collection of n number of integers or arry 
of characters etc.
for eg:

 Take a examination marks of a class.it could b a float 
value or a integer value.Then u need to take five variables 
of float type or interger type.Insted of that u can take an 
array of float or integer type.

  float marks[n];

arrays r mainly used for strings.

     char string[n];

Structure:
The structure is a collection of variables of  various data 
types.

the best example for this is employee details or student 
details.

   struct emloyee
   {
     char name[25];
     int age;
     float salary;
     char mobile[15];
     char desig[25];
   };






   
 
Is This Answer Correct ?    1 Yes 0 No
Fazlur Rahaman Naik
 
  Re: helllo sir , what is the main use of the pointer ,array ,and the structure with the example of a programe
Answer
# 2
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 ?    0 Yes 0 No
Vignesh1988i
 
 
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
write the program for prime numbers? TCS10
What does the message "warning: macro replacement within a string literal" mean?  1
what is c? Tech-Mahindra5
what is a headerfile?and what will be a program without it explain nan example? Assurgent5
can anyone please tell me wat is backlogs... i was looking for the job openings where i read this.. eligibility criteria minimum 70% in degree without backlogs. is that arrear.. if so is it standing arrear or history of arrears... please help me...  4
How can we open a file in Binary mode and Text mode?what is the difference? PanTerra1
Write a program to compare two strings without using the strcmp() function Accenture14
How can I convert integers to binary or hexadecimal?  2
write a c program to check weather a particluar bit is set or not? IBM4
Given a single Linked list with lakhs of nodes and length unknown how do you optimally delete the nth element from the list? Oracle1
Write a program to find the smallest and largest element in a given array in c language Microsoft3
what is const volatile?  1
write a c program to accept a given integer value and print its value in words  3
Write a program that takes three variables(a,b,c) in as separate parameters and rotates the values stored so that value a goes to b,b,to c and c to a  3
why should i select you? Wipro18
will the program compile? int i; scanf(“%d”,i); printf(“%d”,i);  2
How can I set an array's size at run time?  7
dennis ritchie invented C language in AT&T bell laboratory what is the extension of AT&T?  1
main() { float a=3.2e40; printf("%d",a); } Satyam5
given the piece of code int a[50]; int *pa; pa=a; to access the 6th element of the array which of the following is incorrect? a.*(a+5) b.a[5] c.pa[5] d.*(*pa + 5) TCS5
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com