TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maha
NA
0
328.2k
Prefix and Postfix operator
Jul 28 2013 8:25 AM
Continue from
http://www.c-sharpcorner.com/Forums/Thread/220857/code-snippet-functionality.aspx
j is initialized to 1 therefore 1st operand (j++) takes the value of 1. Concurrently 2nd operand also takes the value of 1 but it as a prefix(++j) operator value 1 is
quickly convert
into 2. Therefore k (1+2) must be 3, but in the output k=4 how can this be explained.
using System;
namespace Code
{
class Program
{
static void Main(string[] args)
{
int i, j = 1, k;
for (i = 0; i < 5; i++)
{
k = j++ + ++j;
Console.Write(k + " ");
}
Console.ReadKey();
}
}
}
//4 8 12 16 20
Reply
Answers (
6
)
how to make auto refresh label?
How to Generate Barcode in Crystal Report using Asp.net C#?