What does this declaration in C mean?

Status
Not open for further replies.

Help

Advanced Member level 2
Joined
Feb 15, 2005
Messages
617
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Activity points
7,065
Hi,

Anyone can tell me the statement bellow:

char Key = KEYPAD_...,z;

The code is like that....

Code:
bit KEYPAD_Scan(char* const pKey)
{
	char Key = KEYPAD_NO_NEW_DATA,z;

	if(K0 == 0) {Key = '0';}
	if(K1 == 0) {Key = '1';}
	if(K2 == 0) {Key = '2';}	
	if(K3 == 0) {Key = '3';}
	if(K4 == 0) {Key = '4';}
	if(K5 == 0) {Key = '5';}	
	if(K6 == 0) {Key = '6';}
	if(K7 == 0) {Key = '7';}

	z = *pKey;
.
.
.

Thanks...
 

Re: Declaration in C

this is declaration of char type variables 'Key', and 'z', additional 'Key' variable is initialized with KEYPAD_NO_NEW_DATA constant. KEYPAD_NO_NEW_DATA is probably defined with #define KEYPAD_NO_NEW_DATA some_val
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: Declaration in C

Hi,

You are right, KEYPAD_NO_NEW_DATA is define:
#define KEYPAD_NO_NEW_DATA '*'

but i still not understand ,z ?

Please can you explain detail again or give some simple programe. So that i can understand well.....

Thank you
 

Re: Declaration in C

Code:
char Key = KEYPAD_NO_NEW_DATA,z;

You could also write:

Code:
char Key = KEYPAD_NO_NEW_DATA;
char z;

The comma simply allows you to declare multiple variables of the same type.

So

Code:
char a;
char b;
char c;

a=0;
b=1;
c=2;

and

Code:
char a, b, c;

a=0;
b=1;
c=2;

are the same.
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: Declaration in C

I think KEYPAD_NO..... is a const variable and programmer initillize Key local variable with KEYPAD_NO..... You should control begining of program for KEYPAD_NO....

best luck
 

Re: Declaration in C

Key and z are independent from each othe.

Value of Key is assigened by K0~K7, however value of z is assinged directly by the content of pointer pKey
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…