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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:44:07+00:00 2026-06-13T05:44:07+00:00

I have this piece of code in C: int x = 52706108; if(argc >=

  • 0

I have this piece of code in C:

int x = 52706108;

 if(argc >= 2){
  int val = *argv[1];
  int xor = x^val;
  printf("The xor value between %d and %d is %d in decimal\n",x,val,xor);
 }

I’m compiling it like this:

gcc -m32 -g -o a5_1 a5_1.c

Running it like this:

./a5_1 12

And this is my output:

The xor value between 52706108 and 49 is 52706061 in decimal

I can’t understand why I’m passing the parameter “12” but the machine is reading 49 instead.

  • 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-13T05:44:08+00:00Added an answer on June 13, 2026 at 5:44 am

    That 49 is the ASCII code point of the 1 in your string argument 12. That’s because argv is an array of char pointers, each of which points to a C string containing the argument. So, it’s as if you’ve defined argv[1] to be {'1', '2', '\0').

    If you want to convert the argument to an integer, use something like:

    int num = atoi (argv[1]);
    

    or, preferably with error checking and to avoid undefined behaviour in the event the number is out of range:

    char *nextChar;
    long num = strtol (argv[1], &nextChar, 10);
    if ((nextChar == argv[1]) || (*nextChar != '\0')) {
        // Is either empty or has invalid characters.
        return -1;
    }
    
    // String was non-empty and all-numeric.
    

    Full example:

    #include <stdio.h>
    #include <stdlib.h>
    int main (int argc, char *argv[]) {
        long x = 52706108;
        if (argc >= 2) {
            char *nextChar;
            long val = strtol (argv[1], &nextChar, 10);
            if ((nextChar == argv[1]) || (*nextChar != '\0')) {
                printf ("Invalid input '%s'\n", argv[1]);
                return -1;
            }
            long xor = x^val;
            printf("Xor between %ld and %ld is %ld in decimal\n",x,val,xor);
        }
        return 0;
    }
    

    The output of that program (when given 12 as an argument) is:

    Xor between 52706108 and 12 is 52706096 in decimal
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple piece of code : int a = 1, b =
I have this piece of code: int[] tab2 = {1, 2, 3, 4, 5,
I have this piece of code in C: int q = 10; int s
in C, i have this code piece: int a; a = 10 + 5
I have this piece of code public class Base { private int x=10; void
I have this piece of code: public static DateTime calcMondayDate(DateTime input) { int delta
everyone, I have this piece of the code: void foo(int var, int var1) {
I have this piece of code: ed = (EditText) findViewById (R.id.box); int x =
i have this piece of code int main() { char a[100]; a[0]='a'; a[1]='b'; fun(a[0]);
I have written this piece of code: #include <iostream> using namespace std; double function(int

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.