Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7961041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:55:20+00:00 2026-06-04T04:55:20+00:00

A character array is defined globally and a structure with same name is defined

  • 0

A character array is defined globally and a structure with same name is defined within a function. Why sizeof operator returns different values for c & c++ ?

char S[13];
void fun()
{
    struct S
    {
        int v;
    };
    int v1 = sizeof(S);
}

// returns 4 in C++ and 13 in C

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:55:22+00:00Added an answer on June 4, 2026 at 4:55 am

    Because in C++, the struct you defined is named S, while in C, it’s named struct S (which is why you often see typedef struct used in C code). If you were to change the code to the following, you would get the expected results:

    char S[13];
    void fun()
    {
        typedef struct tagS
        {
            int v;
        } S;
        int v1 = sizeof(S);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a structure which contains character array on C side stuct s {
When we define a character array as 'char name[10]', this indicate that the array
I have a character array defined in a header //header.h const char* temp[] =
I have a function that accepts a variable length array of 80 character strings.
I'm trying to pass an array of character arrays to a C function using
I have a character array and I'm trying to figure out if it matches
I am trying to send across a character array using a transmitter and a
I'm trying to bubble sort a character array in alphabetic order. My code is
I am trying to get my application to convert a character array to uppercase
I am trying to get my application to copy a character array to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.