What definition of #define cont 32767

  • Thread starter woofr_87
  • Start date
  • Tags
    Definition
In summary, the conversation is about the definition and meaning of the code "#define cont 32767" at line 5 in the given source code. The code acts as an alias for the number 32767 and can be used in operations as a literal replacement. It is recommended to use "const int" for type-checking purposes. Further readings on the topic of integers in computer science are also suggested.
  • #1
woofr_87
4
0
Hye.. i got this source code from internet.. i want to ask some quetion..

here is the source code. but not a full code..
PHP:
include <stdio.h>
#include <conio.h>
#include <stdlib.h>

#define  cont 32767

typedef struct dnode
	{
		struct dnode *prev;
		int val;
		struct dnode *next;
	}DNODE;

DNODE *rt;

void insert()
 {
	DNODE *temp,*temp1,*temp2;
	int i;
	printf("\nEnter the value of node:");
	scanf("%d",&i);

	temp=(DNODE*)malloc(sizeof(DNODE));
	temp->val=i;
	if(rt==NULL)
what definition/meaning of "#define cont 32767" at line 5...can someone describe to me...thanks..
 
Physics news on Phys.org
  • #2
It means that "cont" is defined as a kind of alias for the number 32767. So if you would write

int x = cont - 20;

then x would be assigned the value 32767 - 20. Note that the replacement is done by the preprocessor, and is a literal replacement. So by the time your code reaches the compiler it is
int x = 32767 - 20;

In this case, I would recommend making it a proper integer, by using
const int cont = 32767;

Then, whenever you use "cont" in an expression, the compiler can apply type-checking which makes your code safer.
 
  • #3
In addition to CompuChip's response, the number may come from the range of integers in different situations. I can't confirm since the entire code is not pasted and I cannot see its use (Though as previously stated, with the define it is strictly a replacement), but if you are interested in further readings:

http://en.wikipedia.org/wiki/Integer_(computer_science)
http://home.att.net/~jackklein/c/inttypes.html
 
Last edited by a moderator:

FAQ: What definition of #define cont 32767

What is the purpose of #define cont 32767?

The purpose of the #define directive in C and C++ is to create a macro, which is a symbolic name for a value or expression. In this case, #define cont 32767 creates a macro named "cont" that represents the value 32767.

How is #define cont 32767 different from a variable?

Unlike a variable, which can change its value during program execution, a macro created with #define is a constant and its value cannot be modified. It is essentially a text replacement mechanism, where the preprocessor replaces every occurrence of "cont" with "32767" before the code is compiled.

Can I use #define cont 32767 to define other values?

Yes, the #define directive can be used to define any value or expression, as long as it is a valid C or C++ statement. The syntax is #define identifier value, where "identifier" is the name of the macro and "value" is the value or expression it represents.

What happens if I redefine #define cont 32767 with a different value?

If you attempt to redefine a macro that has already been defined, the compiler will issue a warning or error, depending on your compiler settings. It is generally considered bad practice to redefine macros, as it can cause unexpected behavior and make code more difficult to understand.

Can I use #define cont 32767 in other programming languages?

No, #define is a preprocessor directive specific to C and C++ and cannot be used in other programming languages. Other languages may have similar mechanisms for creating constants, but the syntax and behavior will differ.

Similar threads

Replies
1
Views
9K
Replies
3
Views
926
Replies
3
Views
2K
Replies
12
Views
9K
Replies
2
Views
2K
Replies
8
Views
2K
Replies
4
Views
2K
Replies
3
Views
2K
Back
Top