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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:22:40+00:00 2026-05-12T05:22:40+00:00

I came across the following code snippet and needed to predict the output. My

  • 0

I came across the following code snippet and needed to predict the output. My answer was 220 but was told its wrong. Could someone tell me the correct output and please explain why.

using System;
class pointer
{
  public static void Main()
  {
   int ptr1=0;
   int* ptr2=&ptr1;
   *ptr2=220;
   Console.WriteLine(ptr1);
  }
}

EDIT:
Thank you everybody for the explanatory answers. The correct answer is definitely 220 if and only if the above block of code (which is C# code, Sorry for not mentioning it in the question) was declared as unmanaged. Thank you for all your answers. Every one of em was really informative and helpful.

  • 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-12T05:22:40+00:00Added an answer on May 12, 2026 at 5:22 am

    The answer is that it does not compile. You will get the following error:

    error CS0214: Pointers and fixed size buffers may only be used in an unsafe contex

    If, however, you write this:

    int ptr1 = 0;
    
    unsafe {
        int* ptr2 = &ptr1;
        *ptr2 = 220;
    }
    
    Console.WriteLine(ptr1);
    

    Then you will indeed get 220.

    You can also create an entire unsafe method, rather than creating specific unsafe blocks:

    public unsafe void Something() {
        /* pointer manipulation */
    }
    

    Note: you also have to compile with the /unsafe switch (check “Allow unsafe code” in the project properties in Visual Studio)

    Edit: Have a look at Pointer fun with binky for a short, funny, yet informative video on pointers.

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

Sidebar

Related Questions

I have a question regarding the following code snippet I came across in one
While investigating a crash, I came across the following code snippet and immediately recognized
I was studying the Twitter source code, and I came across the following snippet:
I came across the following code snippet in C++ (I am not yet on
I came across the following code snippet on the Scala mailing list: scala> class
I've came across the following code, ok, not exactly but close. The point of
I am learning javascript and I came across the following code snippet: var outerValue
I've been working in backbone.js and came across the following snippet of code. _(view.buttonViews).each(function(button)
I came across the following code, and was told that it means that COL_8888_RED
I came across following code and don't know what does having from twice mean

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.