Developer community
0 votes
57 views
asked by Guru (24.6k points) 31 57 92 | 57 views

1 Answer

0 votes
Best answer
Variables that are defined in a C# program belong to two major categories: value type and reference type. The variables that are based on value type contain a value that is either allocated on a stack or allocated in-line in a structure. The variables that are based on reference types store the memory address of a variable, which in turn stores the value and are allocated on the heap. The variables that are based on value types have their own copy of data and therefore operations done on one variable do not affect other variables. The reference-type variables reflect the changes made in the referring variables.
 
Predict the output of the following code segment: 
 
int x = 42; 
int y = 12;
int w;
object o;
o = x;
w = y * (int)o; 
Console.WriteLine(w);
 
/* The output of the code is 504. */
 
answered by Guru (24.6k points) 31 57 92

Related questions

0 votes
1 answer
0 votes
1 answer
asked by john Guru (27.1k points) 35 52 112 | 72 views
0 votes
1 answer
asked by sara Guru (24.6k points) 31 57 92 | 29 views
0 votes
1 answer
asked by shivani Sr Member (1.1k points) 13 29 42 | 393 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,754 questions
4,046 answers
117 comments
10,709 users