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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:41:15+00:00 2026-06-09T05:41:15+00:00

In the given program: int main() { char *p = \0777; printf(%d %d %d\n,p[0],p[1],p[2]);

  • 0

In the given program:

int main() {
  char *p = "\0777";
  printf("%d %d %d\n",p[0],p[1],p[2]);
  printf("--%c-- --%c-- --%c--\n",p[0],p[1],p[2]);
  return 0;  
}

It is showing the output as:

63 55 0
–?– –7– —-

I can understand that it is converting the first two characters after \0 (\077) from octal to decimal but can any one explain me why 2 characters, why not 1 or 3 or any other ?

Please explain the logic behind this.

  • 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-09T05:41:17+00:00Added an answer on June 9, 2026 at 5:41 am
    char *p = "\07777";
    

    Here a string literal assigned to a pointer to a char.

    "\07777"
    

    In this string literal octal escape sequence is used so first three digits represents a octal number.because rules for octal escape sequence is—

    You can use only the digits 0 through 7 in an octal escape sequence. Octal escape sequences can never be longer than three digits and are terminated by the first character that is not an octal digit. Although you do not need to use all three digits, you must use at least one. For example, the octal representation is \10 for the ASCII backspace character and \101 for the letter A, as given in an ASCII chart.

    SO your string literal stored in memory like

    1st byte as a octal number 077 which is nothing but 63 in decimal and ‘?’ in character

    2nd and 3rd byte as a characters ‘7’ and ‘7’ respectively

    and a terminating character ‘\0’ in last.

    so your answer are as expected 1st,2nd,3d byte of the string literal.

    for more explanation you can visit this web site

    http://msdn.microsoft.com/en-us/library/edsza5ck.aspx

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

Sidebar

Related Questions

Given the following program: #include <stdio.h> int main() { char buf[1024]; scanf(%s, buf); printf(---->
I want to understand how a C++ program that was given to me works,
This program: #include <iostream> #include <cstdlib> #include <string> int main(int argc, const char *argv[])
How to write multithread windows application that runs a program in given number of
I have this program execute with the values 10,20,30 given at command line. int
#include<stdio.h> #include flite.h cst_voice *register_cmu_us_kal(); int main() { cst_voice *v; cst_wave *w; char *text
#include<stdio.h> #include flite.h cst_voice *register_cmu_us_kal(); int main() { cst_voice *v; cst_wave *w; char *text
Given the following program, #include <iostream> using namespace std; void foo( char a[100] )
I'm trying write a C program that sends an UDP packet to a given
I want to write a program that will take substrings from a given string.

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.