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

  • SEARCH
  • Home
  • 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 6535211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:20:48+00:00 2026-05-25T10:20:48+00:00

This program prints all arrays outputs correctly. But how does this program work exactly?

  • 0

This program prints all arrays outputs correctly. But how does this program work exactly? Why do we need address of s[i] here?

#include <stdio.h>

int main(){
        int s[4][2] = {{1234,1},{1233,2},{1232,3},{1331,4}};
        int (*p)[2];
        int i,j,*pint;

        for(i=0;i<4;++i){
                p = &s[i];
                pint = (int*)p;
                printf("\n");
                for(j=0;j<=1;++j)
                        printf("%d ",*(pint+j));
        }
        return 0;
}
  • 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-05-25T10:20:49+00:00Added an answer on May 25, 2026 at 10:20 am

    int (*p)[2] is a pointer to an int [2] type, which itself is essentially a int * type but with some additional type checking on the array bounds.

    So in p = &s[i]; you are setting p to be the address of the pointer to the area in memory where the array s[i] is.

    It’s much much easier to just make p also an array (i.e., “essentially” a pointer to an area in memory with additional machinery), and then use that directly to point at the array memory area (p = s[i]). However, in that case, that’s exactly what pint (as a true pointer instead) is doing, so we can remove p entirely.

    So:

    #include <stdio.h>
    
    int main(){
            int s[4][1] = {{1234,1},{1233,2},{1232,3},{1331,4}};
            int i,j,*pint;
    
            for(i=0;i<4;++i){
                    pint = (int*)s[i];
                    printf("\n");
                    for(j=0;j<=1;++j)
                            printf("%d ",*(pint+j));
            }
            return 0;
    }
    

    See Arrays and pointers or google for “C arrays and pointers” and also Pointer address in a C multidimensional array.

    Note, I assume you are just doing this to play around and understand how pointers and arrays interact, so I make no comment on whether it is ideal to use pointers arithmetic or array notion and so on in each case.


    Note also, that I say an array is “essentially a pointer […]”, however, this is not strictly true, it just acts like a pointer in a lot of cases and for the most part this is a reasonable way to think of how things are working. In reality, arrays are treated in a special way. See Is array name equivalent to pointer? and Arrays.

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

Sidebar

Related Questions

Ok, I want to make my program print out the date: 1/1/2009 But this
For this program #include <iostream> using std::cout; struct C { C() { cout <<
I'm not sure exactly how much this falls under 'programming' opposed to 'program language
I am writing this java program to find all the prime numbers up to
Hey all. I wrote this program for an online contest. It RUNS FINE on
I am still a beginner but I want to write a character-recognition-program. This program
I've two programs I'm using in this way: $ c_program | python_program.py c_program prints
This is my program .when i submit the print button i can print the
This program I use has it's own variables to set when you run it,
This program stores pairs in a map, counting the number of times a word

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.