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                      
tip   SiteMap shows list of All Categories in this site.
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
let's take a code 

struct FAQ
{
int a;
char b;
float c;
double d;
int a[10];
}*temp;

now explain me how the memory will be allocated for the 
structure FAQ and what address will be in the structure 
pointer (temp)....................
 Question Submitted By :: Vignesh1988i
I also faced this Question!!     Rank Answer Posted By  
 
  Re: let's take a code struct FAQ { int a; char b; float c; double d; int a[10]; }*temp; now explain me how the memory will be allocated for the structure FAQ and what address will be in the structure pointer (temp)....................
Answer
# 1
Memory allocated will be word aligned in nature.
e.g. for int the address would be allocated as a multiple of
4 .... Next char would start the n+1 where n = multiple of 4.

Similarly next.... 
when we do sizeof structure we get 60 bytes...
But originally , it should be
4 + 1+ 4+ 8 + 4 *10 = 57 bytes.
The extra three bytes are from char where 3 bytes are wasted
in memory space.
 
Is This Answer Correct ?    1 Yes 2 No
Vrushali
 
  Re: let's take a code struct FAQ { int a; char b; float c; double d; int a[10]; }*temp; now explain me how the memory will be allocated for the structure FAQ and what address will be in the structure pointer (temp)....................
Answer
# 2
please be clear ...............i could not understand ur
reply fully.... please brief it .......sorry
 
Is This Answer Correct ?    0 Yes 0 No
Vignesh1988i
 
 
 
  Re: let's take a code struct FAQ { int a; char b; float c; double d; int a[10]; }*temp; now explain me how the memory will be allocated for the structure FAQ and what address will be in the structure pointer (temp)....................
Answer
# 3
Sorry ..  i did not get your context....
 
Is This Answer Correct ?    1 Yes 1 No
Vrushali
 
  Re: let's take a code struct FAQ { int a; char b; float c; double d; int a[10]; }*temp; now explain me how the memory will be allocated for the structure FAQ and what address will be in the structure pointer (temp)....................
Answer
# 4
see from the above code i want wat address will get stored in the structure pointer temp??????????????
 
Is This Answer Correct ?    0 Yes 0 No
Vignesh1988i
 
  Re: let's take a code struct FAQ { int a; char b; float c; double d; int a[10]; }*temp; now explain me how the memory will be allocated for the structure FAQ and what address will be in the structure pointer (temp)....................
Answer
# 5
55 BYTES OF MEMORY NEEDED.
ADDRESSS-IS BY DEFAULT
 
Is This Answer Correct ?    0 Yes 0 No
Sumanshu
 
  Re: let's take a code struct FAQ { int a; char b; float c; double d; int a[10]; }*temp; now explain me how the memory will be allocated for the structure FAQ and what address will be in the structure pointer (temp)....................
Answer
# 6
As already told by vrushali memory to a structure is always
allocated along word boundaries. So int would fetch 4 bytes
(assumed that the int in ur machine takes 4 and word is 4
bytes). Similarly char would take 1 but since the next entry
i.e. float requires 4 so char would be given 4 (3 extra )
and so on for the remaining summing upto 60 as already
indicated.

By default temp would have the base address of the structure
i.e. pointing to the first integer i.e. 'a' in our case.
 
Is This Answer Correct ?    0 Yes 0 No
Reachhary
 
  Re: let's take a code struct FAQ { int a; char b; float c; double d; int a[10]; }*temp; now explain me how the memory will be allocated for the structure FAQ and what address will be in the structure pointer (temp)....................
Answer
# 7
when u declare a structure there is no memory allocated yet.
memory will be allocated after creating an 
instance(variable).Here, there is an instance (pointer
variable pointing to structure FAQ ). But the compiler
allocated only 4 bytes of memory for the variable temp. But
the this temp contains garbage address or  0 if it is
global. to allocated memory of size 60 byte u need to use
malloc function.

Ex: temp = malloc ( sizeof ( struct FAQ ) );

now 60 bytes of memory has been allocated from the heap. and
the starting address of this memory chunk is stored in
variable temp.
 
Is This Answer Correct ?    1 Yes 0 No
Sharan
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
What is the most efficient way to count the number of bits which are set in a value?  3
program to find a smallest number in an array Microsoft5
what is mallloc()?how it works? Excel3
How to calculate Total working time using Login and logout? Wipro2
what is the definition of storage classes? Wipro2
If we give two names then this displays the connection between the two people. It is nothing but flames game  1
what is the difference between NULL & NUL keywords in C?  3
If "AaBbCc" is passed to the char char x(*a) { a[0]?x(a+1):1; printf("%c",a[0]); return 1; } what will be the output? Hughes5
wats the diference btwen constant pointer and pointer to a constant.pls give examples.  6
Reverse a string word by word??  6
Write a program to print all the prime numbers with in the given range ABC1
Given a single Linked list with lakhs of nodes and length unknown how do you optimally delete the nth element from the list? Oracle1
What are the languages are portable and platform independent?Why they are like that? Excel1
How can I allocate arrays or structures bigger than 64K?  4
what is the difference between c and java?  1
how to make program without <> in library. ADITI1
what is meant by the "equivalence of pointers and arrays" in C? Satyam3
#define MAX(x,y) (x) > (y) ? (x) : (y) main() { int i = 10, j = 5, k = 0; k = MAX(i++, ++j); printf("%d %d %d", i,j,k); } what will the values of i , j and k? } NDS9
what are the difference between ANSI C and Let Us c and Turbo C LG-Soft1
main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } CitiGroup4
 
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