473,387 Members | 1,476 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

when i prints struct type variable it prints more byte then it has data type bytes.

1
when I declare
struct student{
int rollno; //it reserve 4 bytes
char name[25]; // it reserve 25 bytes
float marks; // it reserve 4 bytes
// total is 33byte
};

struct student s1; //it reserve 33 bytes
printf("%d",sizeof(s1));
// it prints 36.
// why prints 36 intead 33 because its total bytes is 33..
Feb 15 '17 #1
1 1130
weaknessforcats
9,208 Expert Mod 8TB
Yes, that can happen. When the compiler sees the struct, it tries to align the members on integer boundaries to simplify locating the members in memory.

I this case the int is on an int boundary and you reserve 4 bytes. The array takes 25 bytes so it extends into the next int area by one byte. The compiler then adds 3 pad bytes so the float starts on the next int boundary.
Feb 15 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: jprunier | last post by:
Hi I isolated this code which gives me odd results and I am not sure to understand why. Basically I declared "positions" as a map that I am using to store pairs of integers. The key used for the...
1
by: ruksan | last post by:
I am using CRecordset in MFC ( VC 6) I created a class derrived from CRecordset to access the table (MS Access) "student" (using ODBC). This derrived class was created using class wizard The...
5
by: nmtoan | last post by:
Hi, I could not find any answer to this simple question of mine. Suppose I have to write a program, the main parts of it are as follows: #include <blahblah.h> struct {
5
by: shivaprasad | last post by:
Hi all, I am a Beginner to c#. I Need to convert array of byte data type to string. How to do this.. ex: byte bytes = new byte; this bytes get filled up. Now I need to convert to string.
1
by: Crirus | last post by:
Is there a way to store a negative value in a byte data type value? I have to store values between -50 and 50 and to use int16 is waiste of space -- Cheers, Crirus ...
9
by: weirdwoolly | last post by:
Hopefully someone will be able to help. I have written a stored procedure in C++ called from a Java test harness to validate the graphic data types in C++ and their use. I have declared the...
4
jeffbroodwar
by: jeffbroodwar | last post by:
Hello, i have a problem about assigning a char value to a byte... please check the code below : ======================================================== Scenario # 1 : This code doesn't work : ...
1
by: aviansh | last post by:
HI Experts, I have same table structures in two database and one master table which contains Table id, Table name,primary key, data type of primary key. i have to comapare Tables in both tha...
9
by: gggram2000 | last post by:
I need some help, cant figure out the error. SqlConnection dbConnection = new SqlConnection(xmldb); dbConnection.Open(); string sql = "SELECT InvStatus FROM SaleReceipts Where AccNum = '" +...
1
by: Krishna C | last post by:
what is the difference b/w VARRAY,RecordType,table type and nested tables data types?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.