473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

what is "#" do in C programming ?

why are these lines marked with #

eg
panel.h

#define LINE_LENGTH 16

I want to define line_length 20

I should take away "#".

please correct me.

Jul 19 '05 #1
9 2005
WW
Mylinux wrote:
why are these lines marked with #
Preprocessor directives.
eg
panel.h

#define LINE_LENGTH 16

I want to define line_length 20
Do you want to define LINE_LENGTH or line_lenght? C is case sensitive.

If you want to define LINE_LENGTH to be 20 instead of 16 just change 16 to
20.
I should take away "#".


No

--
WW aka Attila
Jul 19 '05 #2
Mylinux wrote:
why are these lines marked with #
C and C++ have 2 stage processing.

The first stage is the "c/c++ preprocessor" and anything with a # is
munged by the pre-processor.

The pre-processor manages directives like.
#define
#else
#endif
#if
#ifdef
#include
#line
#pragma

The # must be the first (non whitespace ?) character on the line for the
pre-processor to recognize it.

So, "#define" is a macro define directive. *IMPORTANT* - it is a
textual substitutionm - be VERY carful.

Here is an example where it does not do what you expect
#define CONSTANT 1+2 // constant is 1 plus 2

OK

cout << 100 * CONSTANT; // this is 300 --- right ? WRONG

The macro substitution leads to

cout << 100 * 1+2

which as you know will print 102.

Macros are great for some things but I reccomend you use enums and const
values.

e.g.

enum { CONSTANT = 1+2 };

or

const int CONSTANT = 1+2;


eg
panel.h

#define LINE_LENGTH 16

I want to define line_length 20

I should take away "#".
Write this as:

const int LINE_LENGTH=20;

and nuke the #define.

please correct me.


Jul 19 '05 #3
In article <bk*********@imsp212.netvigator.com>,
Mylinux <my*****@My.com> wrote:
why are these lines marked with #

eg
panel.h

#define LINE_LENGTH 16


They're preprocessor directives. You can read about them in any decent C
or C++ book, or try a Google search on "preprocessor directives".

--
Jon Bell <jt*******@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
Jul 19 '05 #4
so "#" is not a remark in C programming.
if I want to define LINE_LENGTH 16 to 20.

I should in panel.h
....
#DEFINE LINE_LENGTH 20

.....
.....
q2. why it is panel.h, what *.h means?
Jul 19 '05 #5

"Mylinux" <my*****@My.com> wrote in message
news:bk*********@imsp212.netvigator.com...
so "#" is not a remark in C programming.
if I want to define LINE_LENGTH 16 to 20.

I should in panel.h
...
#DEFINE LINE_LENGTH 20
No. All C identifiers and keywords are case sensitive

#define LINE_LENGTH 20

....
....
q2. why it is panel.h,
Ask whomever gave it that name.
what *.h means?


Anything or nothing. It's just part of a file
name where that code is stored.
C++ doesn't care about source file names.
You can use any names which are valid on
your system. '.h' is a quite common form
for header files.
-Mike
Jul 19 '05 #6
"define" should be small case in c programming?
Jul 19 '05 #7
WW
Mylinux wrote:
"define" should be small case in c programming?


Lower case, yes. I suggest you get a good C introductory book. Or use
Google to find an online tutorial. Maybe regulars here can even suggest you
one. But I am afraid if you start programming in C without knowing even the
basics you will do more harm than good to yourself. You will develop a lot
of misconceptions which will harm you later when you program.

C is a very simple language compared to C++. The K&R book (describing
todays ANSI C language) is a very short book. Try to get it.

--
WW aka Attila
Jul 19 '05 #8

"WW" <wo***@freemail.hu> wrote in message
news:bk**********@phys-news1.kolumbus.fi...
Mylinux wrote:
why are these lines marked with #


Preprocessor directives.
eg
panel.h

#define LINE_LENGTH 16

I want to define line_length 20


Do you want to define LINE_LENGTH or line_lenght? C is case sensitive.


It is also spelling sensitive.
Jul 19 '05 #9
jeffc wrote:
I want to define line_length 20


Do you want to define LINE_LENGTH or line_lenght? C is case
sensitive.


It is also spelling sensitive.


Yeah. I hate that part. It should know that when I write lenght I mean
length. :-)

Thanx for pointing out. :-)

--
Attila aka WW
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ken Varn | last post by:
Sometimes when I try to close my managed C++ application, the following dialog displays in Win 2000 Pro: The title of the dialog is "Server Busy". The message is "This action cannot be completed...
17
by: Jared | last post by:
This is going to seem like a generic question that has been posed 1001 times and is probably very subjective, but I need some real world answers, rather than textbook answers. Let me give my...
5
by: Jarek | last post by:
Hi all! I'm optimizing my C++ multi-threaded application (linux). My application consumes huge amout of memory from unknown reason. There are no memory leaks, or other allocation bugs,...
1
by: blue | last post by:
Looking at code from the following: http://www.gamedev.net/reference/programming/features/enginuity2/page3.asp I'm confused though... CMMPointer(T *o) { obj=0; *this=0;
5
by: junky_fellow | last post by:
Each time i submit some pattern to "google", it shows search took 0.XX seconds for exploring millions of web pages. When i look for efficient ways of searching a string, they always say compare...
2
by: Lasse Edsvik | last post by:
Hello I was wondering if you guys could tell me if: cmd.ExecuteReader(CommandBehavior.CloseConnection); returns a dataset, datatable or what?
1
by: Alan Silver | last post by:
Hello, I have the following line of code in a script... litMsg.Text = Server.MapPath("/"); where litMsg is an ASP.Net Literal control. When I try and run this page, I get the error ... ...
9
by: Dullme | last post by:
i can hardly know what is the code for this. I have researched palindromes, but unfortunately, I only have read about integers not for characters..I need some help..
5
by: cowgurl art | last post by:
Hey there. I will not pretend to know more than I do...I'm just getting my feet wet with Dreamweaver and MySql databases. What I'm trying to do is create a form that will allow members to submit an...
4
by: CBFalconer | last post by:
regis wrote: Why don't you read the documentation (or source) from whomever supplied you that (non-standard) function? -- : Chuck F (cbfalconer at maineline dot net) :...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.