valid code?


 
Thread Tools Search this Thread
Top Forums Programming valid code?
# 1  
Old 10-20-2006
valid code?

hey , everyone. I have a few questions about pieces of code and was wondering if someone could tell me what exactly they did or if they are even valid.

bool1 && bool2 || bool3 <---in what order do these get processed?
if (! isdigit(c)) <---What does this do?
i = j % 3; <---what does this do?
a+b *c <---what order do these get processed?

Are any of these lines valid code?
i;
short int s;
long int L;
long long LL;

thanks everyone.
# 2  
Old 10-20-2006
bool1 && bool2 || bool3 <---in what order do these get processed?

Left to right: bool1 then bool2, if they both return true then bool3 is ignored.
If they fail then bool3 is tested

if (! isdigit(c)) <---What does this do?

returns true when C is any non-numeric character - punctuation, aplhabetic, etc.

i = j % 3; <---what does this do?

i is assigned the remainder (modulo) if the value of j divided by 3. ie if j is 5, 5 mod 3 = 2 - so 2 is assigned to the variable i.

a+b *c <---what order do these get processed?

multiplication then addition so a is added to the value of b*c

This sounds like homework....
# 3  
Old 10-20-2006
Code:
bool1 && bool2 || bool3

&& has higher precedence than || .Associativity is from left to right.
first bool1 && bool2 is executed and then with bool3.
If bool1 expression is false then bool2 expression is not executed.
If result of bool1 && bool2 is true then bool3 expression is not executed

Code:
if (! isdigit(c)) 

Negates the result of isdigit(c)

Code:
i = j % 3 

% modulus operator which gives the remainder

Code:
a+b *c

* has higher precedence than +. Associativity is from left to right.
Above one is similar to a + (b*c)
# 4  
Old 10-20-2006
hey thanks, cleared that right up for me. what about those last few lines, are any of those valid code?

Oh, lol nope not homework, just wondering what would happen if i didn't put in brackets on some of these things. and what c is willing and not willing to do.
# 5  
Old 10-20-2006
Quote:
Originally Posted by bebop1111116
Are any of these lines valid code?
i;
Only if there is a variable 'i' declared in scope. But while valid, it's totally useless, the statement has no effect.
Quote:
short int s;
long int L;
long long LL;
The first two are valid. 'long int' is redundant, since 'long L' will declare the same type of variable. The actual sizes of the integers varies from platform to platform, but the order of sizes is always:

sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(void *) <= sizeof(long)

Note how sizeof(int) isn't guaranteed to be equal to siezof(void *) -- it can also be smaller. It's usually the same on 32-bit platforms, but assuming it's safe to cast pointer to int has caused many headaches on 64-bit systems, where pointers are suddenly twice as large!

If fixed sizes are needed for integers, like a guaranteed 32-bit type, use the types declared in stdint.h.

'long long' is a gcc extension for 64-bit integers on 32-bit platforms. Different compilers have different ways of doing this. Again, use the 64-bit type from stdint.h instead.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to check for valid password

I need to check if an account has a valid password. Would something like this work? read ACCNAME if grep -q "^$ACCNAME:\$6:" /etc/shadow; thenI noticed every entry in my shadow file that has a password starts with $6 ... it works for my current setup, but would it always work? I can't test... (4 Replies)
Discussion started by: ADay2Long
4 Replies

2. UNIX for Dummies Questions & Answers

Is this valid tar statements ?

Hello every one, Is this a valid tar statement ? tar cv /dev/rmt/0 /etc tar cx /dev/rmt/0 /opt tar c /dev/rmt/0 and what is there effect ? Thanks in advance. (3 Replies)
Discussion started by: drdigital_m
3 Replies

3. UNIX for Dummies Questions & Answers

Testing for valid DC's?

Ok so this is sort of a unix question. I am frequently logging into customers boxes and our product integrates with Active directory. I deal with a great deal of people who have no business being admins but are and they don't know squat about their network or their DC's. So a recurring problem... (4 Replies)
Discussion started by: MrEddy
4 Replies

4. Homework & Coursework Questions

Valid Name

Could someone help me by midnight tonight!!! Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Insert a reference to the Bourne shell as the command... (0 Replies)
Discussion started by: cody007
0 Replies

5. Shell Programming and Scripting

Specified substitution not valid for

Experts, In a script i get the following error: The specified substitution is not valid for this command Do you have any idea what is wrong with it? TITLE="Code Checker" # Script Titel # EXT="_UA99" # Eind van dirnaam # FILE="job.dat" # Zoekbestandsnaam # SEARCH="returncode 0" #... (1 Reply)
Discussion started by: klaasjan
1 Replies

6. Programming

is it valid output ?

#include <iostream> #include<stdio.h> using namespace std; class a { public: int xx; a() { cout << "in CONS a \n"; } ~a() { cout << "in DES a \n"; } }; (1 Reply)
Discussion started by: crackthehit007
1 Replies

7. Shell Programming and Scripting

': not a valid identifier

I am trying to write a bash script. I am able to do simple things like pass arguments, assign variables and echo the results. However, when I try to declare and array or anything a little more complicated I get ': not a valid identifier Here is my code so far: #!/bin/bash echo start t... (7 Replies)
Discussion started by: script123
7 Replies

8. Solaris

Are my computer valid for Solaris

hello It's my first post in your forum I have a Pentium 4 processor and Motherboard Gigabyte with Intel chipset and 80 GB hard disk .My question is : Are my computer valid for Solaris os ??? Are the Solaris is free like Fedora and Suse ?? (sorry for my bad English because I'm not English man) (3 Replies)
Discussion started by: engshaheen
3 Replies

9. Shell Programming and Scripting

Is this a valid statement?

I need an if statement that recognizes whether files fitting a certain pattern exist in the current directory. Is this syntax valid: if ; then ... fi assuming that zero="0" and star="*". Is there a better way to write it? (3 Replies)
Discussion started by: mharley
3 Replies
Login or Register to Ask a Question