C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - True / False Questions (Q.No. 11)
11.
On declaring a structure 0 bytes are reserved in memory.
Discussion:
20 comments Page 2 of 2.
Avishek said:
1 decade ago
When a structure is declared no memory space is allocated till a variable is declared.
Then how can the answer be false ?
Then how can the answer be false ?
A v said:
1 decade ago
#include<stdio.h>
#include<string.h>
int main()
{
typedef struct
{
int a;
int m;
} stu;
printf("%d",sizeof(stu ));
return 0;
}
This gives 8 in code block, that means memory is allocated at time of decleration
#include<string.h>
int main()
{
typedef struct
{
int a;
int m;
} stu;
printf("%d",sizeof(stu ));
return 0;
}
This gives 8 in code block, that means memory is allocated at time of decleration
Naresh said:
1 decade ago
Here Structure reserved one bytes when it declare without any member declare inside it.
Ingale Yogesh said:
1 decade ago
Memory is allocated only when an instance of structure is created, till no memory is allocated.
Subhra said:
1 decade ago
Answer is not correct ,because at the time of declaring the structure no memory space is allocated, but when we define it,then the memory is allocated...example
case 1:
struct student
{
int roll;
};//memory allocation not done
void main()
{
printf("hello");
}
case 2:
struct student
{
int roll;
};//memory allocation still not done
void main()
{
struct stdent s1;//now the allocation is done
printf("hello");
}
case 1:
struct student
{
int roll;
};//memory allocation not done
void main()
{
printf("hello");
}
case 2:
struct student
{
int roll;
};//memory allocation still not done
void main()
{
struct stdent s1;//now the allocation is done
printf("hello");
}
Nikhil said:
1 decade ago
If mem is allocated when struct is declare can you tell me how many bytes declare at that time.
Umesha krishnegowda said:
1 decade ago
NO, answer is not correct. Because after structure variable is declared then only memory will allocated.
Sachin kakatkar said:
1 decade ago
sorry The memory is allocated when structure is declared .the memory not allocated when structure is defined. so answer is correct.
Amit pawar. said:
1 decade ago
the memory will be allocated only after structure variables are declared.
then how the answer is false.
then how the answer is false.
Harshith M L said:
1 decade ago
Yep only after a variable is declared memory will be allocated till then no memory will be allocated.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers