Combining Operators


 
Thread Tools Search this Thread
Top Forums Programming Combining Operators
# 1  
Old 05-26-2014
Combining Operators in C

Hey everyone, I'm really getting into learning C, but as I look at more advanced example code, I see things like
Code:
if (!*variable1) 
blah blah blah...


and

Code:
variable2 ^= *(variable1++);

my question is, when you have a combination of two operators, like !*. The ! means 'not' and the * means a pointer, so for
!* variable1
does this just mean 'if not a pointer'?

For most combinations of operators do you just combine both of their literal meanings?

Last edited by Lost in Cyberia; 05-26-2014 at 10:39 PM..
# 2  
Old 05-26-2014
Code:
if(*var)

evaluates to true if the object pointed to by var is non-zero.
Code:
if(!*var)

evaluates to true if the object pointed to by var is not non-zero (i.e. is zero).

Code:
variable2 ^= *(variable1++)

sets variable2 to the exclusive or of variable2 and the value pointed to by variable1, and then increments variable1 to point to the next object in the array of objects into which variable1 points.

In your C reference look for a section that talks about operator precedence.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 05-28-2014
I see! Thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash -o -v -R operators

I do not know the use of the -o -v -R operators. This is what the info says and I am confused of what optname and varname mean, are they just normal variable? -o optname True if the shell option optname is enabled. See the list of options under the ... (6 Replies)
Discussion started by: kristinu
6 Replies

2. Shell Programming and Scripting

Array operators

Hi Lets say I have two arrays: VAR_1 = "File_A" "File_B" "File_C" "File_D" VAR_2 = "File_A" "File_D" Is there a simple command to get the difference of these list, i.e. VAR_1_2 = "File_B" "File_C" or do I have to write a script and loop through all elements and compare them one by one? ... (1 Reply)
Discussion started by: Wernfried
1 Replies

3. Shell Programming and Scripting

Miscellaneous operators

Hi everyone, I read some shell script code,then I have some issue. the following code. let "t1 = ((5 + 3, 7 - 1, 15 - 4))" echo "t1 = $t1" t1=11 Here t1 is set to the result of the last operation.why? (3 Replies)
Discussion started by: luoluo
3 Replies

4. Homework & Coursework Questions

Operators

I really don't know the meaning of these operators. Could someone explain the meanings? <, <=, ==, !=, >=, >, ||, &&, ! ~ , !~ Thanks! (1 Reply)
Discussion started by: Erjen
1 Replies

5. Shell Programming and Scripting

Operators

I really don't know the meaning of these operators. Could someone explain the meanings so I can make my test for today? <, <=, ==, !=, >=, >, ||, &&, ! ~ , !~ Thanks! (1 Reply)
Discussion started by: Erjen
1 Replies

6. UNIX for Dummies Questions & Answers

Operators

I am trying to understand Does the following: {tmp+=$10} Mean take $10 and add them all up and call it tmp thanks! (2 Replies)
Discussion started by: llsmr777
2 Replies

7. UNIX for Dummies Questions & Answers

Arithmetic Operators

Hello, I have a list of 'inputs' and i want to convert those on the second list named 'Desired Outputs', but i don't know how to do it? Inputs Desired Outputs 1 2 94 4 276 8 369 10 464 12 ... (0 Replies)
Discussion started by: filda
0 Replies

8. UNIX for Advanced & Expert Users

If with set operators

Hi guys, I'm trying to run more than one "if" condition at once. What I want is something like if ] or ] or ]; then ... I can't remember the syntax for using this or/and set operators. Can someone please assist/ jog my memory? thanks Khoom (2 Replies)
Discussion started by: Khoomfire
2 Replies

9. UNIX for Advanced & Expert Users

bitwise operators

can anybody write a program to divide a number by another number using bitwise operators (9 Replies)
Discussion started by: areef4u
9 Replies
Login or Register to Ask a Question