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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:00:59+00:00 2026-05-26T19:00:59+00:00

#include<stdio.h> int main(){ char a[6],*p; a[0]=’a’; a[1]=’b’; a[2]=’c’; a[3]=’4′; a[4]=’e’; a[5]=’p’; a[6]=’f’; a[7]=’e’; printf(%s\n,a);

  • 0
#include<stdio.h>
int main(){

char a[6],*p;

a[0]='a';
a[1]='b';
a[2]='c';
a[3]='4';
a[4]='e';
a[5]='p';
a[6]='f';
a[7]='e';
printf("%s\n",a);
printf("printing address of each array element");
p=a;

printf("%u\n",&p[0]);
printf("%u\n",p+1);
printf("%u\n",a+2);
return 0;
}

The output is as follows…

anusha@anusha-laptop:~/Desktop/prep$ ./a.out
abc4epfe
printing address of each array element3216565606
3216565607
3216565608

When I declared the array as char a[6] why is it allowing me to allocate a value at a[7]? Does it not need a null character to be appended for the last element?

Also p=a => p holds the address of first element of char array a. I don’t understand how it is correct to place an ‘&’ in front of an address (p[0]). &p[0] means address of address of first element of a which doesn’t make any sense, at least to me.

Why is it printing the correct output?

  • 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-26T19:01:00+00:00Added an answer on May 26, 2026 at 7:01 pm

    You have just invoked undefined behaviour. There’s little point in reasoning about writing beyond the bounds of an array. Just don’t do it.

    &p[0] means address of address of first element of a[] which is not sensible

    No, that’s perfectly sensible. Your description perfectly describes what is going on. &p[0] is the same as p which is the same as a. When you write p[0] you are dereferencing the pointer. When you then write &p[0] you are taking the address of that variable and thus return to what you started from, p.

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

Sidebar

Related Questions

#include<stdio.h> int main() { char a, b; scanf(%c, &a); scanf(%c, &b); printf(%c %c,a,b); return
#include<stdio.h> int main() { char str[25] = helloworld; printf(%s %s, &str+2,str+2); return 0; }
#include <stdio.h> int main() { char temp[1024]; if(getchar() != 'y') { printf(no options\n); return
#include <stdio.h> #include <stdlib.h> int main() { char *str=Helloworld; printf(%d,printf(%s,str)); return 0; } output
#include<stdio.h> int main() { char a='x'; printf(%c %d,a); return 0; } Output: x 134513696
#include<string.h> #include<stdio.h> int main() { char* charPtr=see me; printf(%s\n, charPtr); printf(%d, charPtr); return 0;
#include<stdio.h> #include<string.h> int main() { char a[]=aaa; char *b=bbb; strcpy(a,cc); printf(%s,a); strcpy(b,dd); printf(%s,b); return
consider the code #include<stdio.h> int main(void) { char* a; scanf(%s,a);//&a and &a[0] give same
#include <stdio.h> int main() { char TurHare; while(1) { scanf(%c,TurHare); printf(\nCharacter :%c, TurHare); }
#include<stdio.h> #include<ctype.h> int main() { char a,b; FILE *fp; fp=fopen(lext.txt,w); fprintf(fp,PLUS); return 0; }

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.