Difference between some if statements C++

  • Context: Comp Sci 
  • Thread starter Thread starter asz304
  • Start date Start date
  • Tags Tags
    C++ Difference
Click For Summary

Discussion Overview

The discussion revolves around the differences in behavior between two types of if statements in C++, the use of two-dimensional arrays, and methods for changing the brightness of an image using a specific formula. The scope includes technical explanations and conceptual clarifications related to programming in C++.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • Some participants note that the first if statement checks if 'a' is non-zero, while the second checks if 'a' is negative, leading to different execution conditions.
  • One participant explains that two-dimensional arrays can represent data in a grid format, useful for applications like graphics and game boards.
  • Another participant questions the formula for changing brightness, suggesting it may be incorrect and discussing the relationship between color values and brightness.
  • There is a suggestion that using pass by reference may be necessary for changes to persist outside of a function, but this is left uncertain.

Areas of Agreement / Disagreement

Participants express differing views on the formula for brightness adjustment and the necessity of using pass by reference, indicating that there is no consensus on these points.

Contextual Notes

Some assumptions about the behavior of if statements and the correctness of the brightness formula remain unresolved, as do the specific requirements for using two-dimensional arrays in different contexts.

asz304
Messages
107
Reaction score
0
Say for example
Code:
 int a = 0; 
if ( a ){
...
}


int a = 0;
if ( a < 0 ){
...
}

What's different with the first if statement? or do they have the same meaning?

Thanks

EDIT: What is the use of two-dimensional arrays? I see it mostly in file input output stream stuff.

And how do I change the brightness of a picture using c++ using this formula:

R2 = G2 = B2 = (R1 + G1 + B1)/3

Do I need to use pass by reference?
 
Last edited:
Physics news on Phys.org
In this case nothing, the loop doesn't execute for a=0

The first one will execute for any value of 'a' other than 0, the second will execute for any negative 'a'
 
asz304 said:
Say for example
Code:
 int a = 0; 
if ( a ){
...
}


int a = 0;
if ( a < 0 ){
...
}

What's different with the first if statement? or do they have the same meaning?

Thanks

EDIT: What is the use of two-dimensional arrays? I see it mostly in file input output stream stuff.
Two-dimension arrays are useful if you have information that's in tables. One application of arrays like this is in graphics. Years ago you could write programs that would store strings of bytes to a particular location in memory that would change what was on the computer screen. Different modes (such as text vs. high resolution graphics) used memory at different locations and different amounts of memory. The screen is two-dimensional, with each row of letters or pixels corresponding to a row in a two-D array. A program could initialize an array and write it to memory and the screen would change.


asz304 said:
And how do I change the brightness of a picture using c++ using this formula:

R2 = G2 = B2 = (R1 + G1 + B1)/3

Do I need to use pass by reference?
You need to use some graphics library that has functions that change what is displayed on the screen, change the brightness, and so on. I would have to know more about what is available in the graphics package to be able to answer your question.
 
asz304 said:
Say for example
Code:
EDIT: What is the use of two-dimensional arrays? I see it mostly in file input output stream stuff.

And how do I change the brightness of a picture using c++ using this formula:

R2 = G2 = B2 = (R1 + G1 + B1)/3

Do I need to use pass by reference?[/QUOTE]

1. 2D arrays are a representation of a discrete surface: most commonly a grid. The game board of battleship comes to mind as does [PLAIN]"[URL[/PLAIN]  Game of Life[/URL], and off-course an pixel map.

2. Thats a strange formula, its probably wrong. The higher the number for each color the closer it is to white. SO, 255-255-255 is white and 000-000-000 is black. Its possible to make things whiter/lighter(?) by addition of positive increments. 

3. I don't know do you? Probably or else the changes won't carry over in the function output.
 
Last edited by a moderator:

Similar threads

  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 7 ·
Replies
7
Views
7K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 23 ·
Replies
23
Views
9K