TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Dennis Brown
from: George White
date: 1998-09-19 08:04:02
subject: Tutorial questions?

Hi Dennis,

You asked:

DB>I'm working my way through the C tutorial and have a couple of
DB>questions, if I may...
DB>1) What is the difference between "static int answer=45" and
DB> "const int answer=45"?  If I'm reading it right, don't
they both do the
DB>same thing?

No they don't.
A static value has a fixed location and persists between calls, but can
change it's value.
A const int has a fixed value, and cannot be assigned to.

DB>2) I understand what a Shift left(<<)  and Shift right
(>>) does, but I
DB>don't understand in what situation one would be needed!  Isn't 5<<1=10
DB>the same as 5*2=10, and 6>>1=3 the same as 6/2=3?

As it moves all the bits in a value the appropriate number of places and
fills the vacant locations with 0 bits if you have a situation where
things can move varying distances it is simpler to code and shows more
clearly what is happening than using division and multiplication.

George

 * SLMR 2.1a * Computers eliminate spare time.

--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-717904) (2:440/4)
SEEN-BY: 396/1 622/419 632/0 371 633/260 267 270 371 634/397 635/506 728 810
SEEN-BY: 639/252 670/218
@PATH: 440/4 255/1 251/25 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.