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 8941123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:13:41+00:00 2026-06-15T11:13:41+00:00

Here is my sample code #include<stdio.h> void main() { int arr[]={1,2,3,4,5,6}; char *ptr,a; a=’c’;

  • 0

Here is my sample code

#include<stdio.h>
void main()
{
 int arr[]={1,2,3,4,5,6};
 char *ptr,a;
 a='c';
 ptr=&a;
 int *ptr1,a1;
 a1=4;
 ptr1=&a1;
 printf("%d  %d   %d",sizeof(arr), sizeof(ptr1), sizeof(ptr));
}

Now, as far as I understand, size of will tell me the size required to store the variable, now the output for this one is

24 4 4

Why is the size of arr=24, after all it’s just a pointer and it should be having size =4 ?

Thanks.

  • 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-15T11:13:42+00:00Added an answer on June 15, 2026 at 11:13 am

    “…after all it’s just a pointer…”? No. Array is not a pointer. Array is an array object: a solid continuous block of memory that stores the array elements, no pointers of any kind involved. In your case array has 6 elements of size 4 each. That is why your sizeof evaluates to 24.

    The common misconception about arrays being pointers has been debunked millions of times, but somehow it continues to pop up now and then. Read the FAQ, come back if you have any questions about it

    http://c-faq.com/aryptr/index.html

    P.S. As @Joachim Pileborg correctly noted in his answer, sizeof is not a function. It is an operator.


    Another context in which arrays behave differently from pointers is the unary & operator (the “address of” operator). When unary & is applied to a pointer of type int * is produces a pointer of type int **. When unary & is applied to an array of type int [10] is produces a pointer of type int (*)[10]. These are two very different types.

    int *p = 0;
    int a[10] = { 0 };
    
    int **p1 = &p;      /* OK */
    int **p2 = &a;      /* ERROR */
    int (*p3)[10] = &a; /* OK */
    

    It is another popular source of questions (and errors): sometimes people expect & to produce a int ** pointer when applied to an int [10] array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got the following simple C++ code: #include <stdio.h> int main(void) { ::printf(\nHello,debugger!\n); }
Here's the sample code: public static void col (int n) { if (n %
here's a simple and short code I've been trying to run: #include <stdio.h> int
Here is the sample code that I ran on Visual Studio 2010: #include <iostream>
Here's a sample code: #include <stack> #include <cstddef> template <std::size_t N, template <class> class
my sample code is here include 'simple_html_dom.php'; function get_all_links($url){ global $host; $html = new
Here's the sample code: class TestAO { int[] x; public TestAO () { this.x
I have the following code: #include<stdio.h> #include<semaphore.h> #include<pthread.h> sem_t semr; void* func(void* i) {
I wrote a simple url parser using strtok(). here's the code #include <stdio.h> #include
I came across the sample code. assuming_order_of_execution_pitfall.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include

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.