Search Results

Search found 2508 results on 101 pages for 'ternary operator'.

Page 25/101 | < Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >

  • Parenthesis operator in C. What is the effect in the following code

    - by Andre
    Hi everyone, I was playing with a macro to enable/disable traces when I came out with the following code when the macro is disabled: int main { ("Hello world"); } This code is valid and I got the desired effect (nothing happens when the macro is disabled) but I couldn't figure out what exactly is happening. Is the compiler seeing the parenthesis as a "nameless" method declaration? To make it clearer the code is : #ifdef TRACE #define trace printf("%s %d -> ",__FILE__, __LINE__);printf else #define trace #endif int main { trace("Hello world"); } Thanks in advance.

    Read the article

  • PG::Error: ERROR: operator does not exist: integer ~~ unknown

    - by rsvmrk
    I'm making a search-function in a Rails project with Postgres as db. Here's my code def self.search(search) if search find(:all, :conditions => ["LOWER(name) LIKE LOWER(?) OR LOWER(city) LIKE LOWER(?) OR LOWER(address) LIKE LOWER(?) OR (venue_type) LIKE (?)", "%#{search}%", "%#{search}%", "%#{search}%", "%#{search}%"]) else find(:all) end end But my problem is that "venue_type" is an integer. I've made a case switch for venue_type def venue_type_check case self.venue_type when 1 "Pub" when 2 "Nattklubb" end end Now to my question: How can I find something in my query when venue_type is an int?

    Read the article

  • C: switch case with logical operator

    - by Er Avinash Singh
    While I am new to c and want help in this program my code is : #include<stdio.h> #include<conio.h> void main(){ int suite=2; switch(suite) { case 1||2: printf("hi"); case 3: printf("byee"); default: printf("hello"); } printf("I thought somebody"); getche(); } I am working in turbo c and it shows no error and the output is helloI thought somebody Please, let me know how is this working ??? note :- here break is not the case as I intentionally left them.

    Read the article

  • How does the " is " operator work internally

    - by JDMX
    I want to compare the type of an object to a type to see if they are the same. I do not have the object, just the type of the object. I can do type1 == type2 and get general equality I can have a recursive loop where I repeat the above step for type1.BaseType until the BaseType is null. I can do type1.GetInterface( type2.FullName ) != null to check if type2 is an interface of type1 If I put it all together, I get if ( type2.IsInterface ) return type1.GetInterface( type2.FullName ) != null; while ( type1 != null ) { if ( type1 == type2 ) return true; type1 = type1.BaseType; } return false; Is that all the is keyword is. I cannot find the right keyword to plug into the Reflector search to find the function and a google search on "is" was not really helpful

    Read the article

  • Strange behavior of std::cout &operator<<...

    - by themoondothshine
    Hey ppl, I came across something weird today, and I was wondering if any of you here could explain what's happening... Here's a sample: #include <iostream> #include <cassert> using namespace std; #define REQUIRE_STRING(s) assert(s != 0) #define REQUIRE_STRING_LEN(s, n) assert(s != 0 || n == 0) class String { public: String(const char *str, size_t len) : __data(__construct(str, len)), __len(len) {} ~String() { __destroy(__data); } const char *toString() const { return const_cast<const char *>(__data); } String &toUpper() { REQUIRE_STRING_LEN(__data, __len); char *it = __data; while(it < __data + __len) { if(*it >= 'a' && *it <= 'z') *it -= 32; ++it; } return *this; } String &toLower() { REQUIRE_STRING_LEN(__data, __len); char *it = __data; while(it < __data + __len) { if(*it >= 'A' && *it <= 'Z') *it += 32; ++it; } return *this; } private: char *__data; size_t __len; protected: static char *__construct(const char *str, size_t len) { REQUIRE_STRING_LEN(str, len); char *data = new char[len]; std::copy(str, str + len, data); return data; } static void __destroy(char *data) { REQUIRE_STRING(data); delete[] data; } }; int main() { String s("Hello world!", __builtin_strlen("Hello world!")); cout << s.toLower().toString() << endl; cout << s.toUpper().toString() << endl; cout << s.toLower().toString() << endl << s.toUpper().toString() << endl; return 0; } Now, I had expected the output to be: hello world! HELLO WORLD! hello world! HELLO WORLD! but instead I got this: hello world! HELLO WORLD! hello world! hello world! I can't really understand why the second toUpper didn't have any effect.

    Read the article

  • SQL AND operator not working properly

    - by Chandana De Silva
    I have following two tables LandParcels Table Blockid ParcelNo storPri ======= ======== ======= 52000105 3 State 52000105 4 Private 52000105 5 State Actions Table Blockid ParcelNo ActionTaken ======= ======== =========== 52000105 3 Received 52000105 3 Send to Computer 52000105 4 Received 52000105 5 Received I want to find the records Received but not Send to Computer Here is my query select l.blockid, l.parcelno from landparcels l left join actions ac on l.blockid = ac.blockid and l.parcelno = ac.parcelno where ac.actiontaken = 'Received' and ac.actiontaken <> 'Send to Computer' and ac.blockid = 52000105 The result is Blockid ParcelNo ======= ======== 52000105 3 52000105 4 52000105 5 I want ParcelNo 4 and 5

    Read the article

  • Is the ruby operator ||= intelligent?

    - by brad
    I have a question regarding the ||= statement in ruby and this is of particular interest to me as I'm using it to write to memcache. What I'm wondering is, does ||= check the receiver first to see if it's set before calling that setter, or is it literally an alias to x = x || y This wouldn't really matter in the case of a normal variable but using something like: CACHE[:some_key] ||= "Some String" could possibly do a memcache write which is more expensive than a simple variable set. I couldn't find anything about ||= in the ruby api oddly enough so I haven't been able to answer this myself. Of course I know that: CACHE[:some_key] = "Some String" if CACHE[:some_key].nil? would achieve this, I'm just looking for the most terse syntax.

    Read the article

  • Shift operator in Java bizarre program output

    - by Umesh Kacha
    I came across the following program and it behaving in unexpected manner. public class ShiftProgram { public static void main(String[] args) { int i = 0; while(-1 << i != 0) i++; System.out.println(i); } } If we think about this program output, when it reaches 32 while loop condition should return false and terminate and it should print 32. If you ran this program, it does not print anything but goes into an infinite loop. Any idea whats going on? Thank you in advance.

    Read the article

  • using 'or' operator not working for menu

    - by John Wilkes
    In my code here, I have a CSS class called "active" which I use if the $_GET['page'] == tutorials, php, mysql, etc... The problem is, even if the 'page' variable is not equal to any of these values, the Tutorials button in this case is still active for some reason. Any ideas why this would be happening? Am I using the 'or' (||) operand incorrectly? <?php if($_GET['page'] == 'tutorials' || 'php' || 'mysql' || 'html' || 'css' || 'js') { ?> <li class="active"> <?php } else { ?> <li> <?php } ?> <a href="index.php?page=tutorials">Tutorials</a> <ul> <li><a href="index.php?page=php">PHP</a></li> <li><a href="index.php?page=mysql">MySQL</a></li> <li><a href="index.php?page=html">HTML</a></li> <li><a href="index.php?page=css">CSS</a></li> <li><a href="index.php?page=js">JS</a></li> </ul> </li>

    Read the article

  • Using the AND and NOT Operator in Python

    - by NoahClark
    Here is my custom class that I have that represents a triangle. I'm trying to write code that checks to see if self.a, self.b, and self.c are greater than 0, which would mean that I have Angle, Angle, Angle. Below you will see the code that checks for A and B, however when I use just self.a != 0 then it works fine. I believe I'm not using & correctly. Any ideas? Here is how I am calling it: print myTri.detType() class Triangle: # Angle A To Angle C Connects Side F # Angle C to Angle B Connects Side D # Angle B to Angle A Connects Side E def __init__(self, a, b, c, d, e, f): self.a = a self.b = b self.c = c self.d = d self.e = e self.f = f def detType(self): #Triangle Type AAA if self.a != 0 & self.b != 0: return self.a #If self.a > 10: #return AAA #Triangle Type AAS #elif self.a = 0: #return AAS #Triangle Type ASA #Triangle Type SAS #Triangle Type SSS #else: #return unknown

    Read the article

  • Prefix and Postfix operator's necessity

    - by Karthi prime
    What is the necessity of both prefix and postfix increment operators? Is not one enough? To the point, there exists like a similar while/do-while necessity problem, yet, there in no so much confusion (in understanding and usage) in having them, but with having both prefix and postfix (like priority of these operators, their association, usage, working). And do anyone been through a situation where you saidd "Hey, I am going to use postfix increment. Its useful here"

    Read the article

  • Providing *implicit* conversion operator for template specialization

    - by Neil G
    I have a templated sparse_vector<T> class, and I am also using Boost UBLAS. How would I provide implicit conversions between sparse_vector<double> and boost::numeric::ublas::compressed_vector<double>? I would also like to provide similar conversions between std::vector<double> and boost::numeric::ublas::vector<double>. (I am using gcc 4.4 with C++0x enabled.)

    Read the article

  • Unexpected variable update when using bash's $(( )) operator for arithmetic

    - by philo
    I'm trying to trim a few lines from a file. I know exactly how many lines to remove (say, 2 from the top), but not how many total lines are in the file. So I tried this straightforward solution: $ wc -l $FILENAME 119559 my_filename.txt $ LINES=$(wc -l $FILENAME | awk '{print $1}') $ tail -n $(($LINES - 2)) $FILENAME > $OUTPUT_FILE The output is fine, but what happened to LINES?? $ wc -l $OUTPUT_FILE 119557 my_output_file.txt $ echo $LINES 107 Hoping someone can help me understand what's going on.

    Read the article

  • Array increment operator

    - by Stardust
    Could any one please tell me the meaning of "++" with array in the following code in Java: int [ ] arr = new int[ 4 ]; for(int i = 0; i < arr.length; i++){ arr[ i ] = i + 1; System.out.println(arr[ i ]++); } what is arr[ i ]++ meaning in above code, and why we can't do like: arr[ i ]++ = i + 1;

    Read the article

  • Simple question about operator ||

    - by Tristan
    HEllo, i try to do that in FlashBuilder (FlexProject) protected function btn_detail_view_clickHandler(event:MouseEvent):void { CurrentState="Statistiques" || "PartMarche"; } But it's not working, i guess this is not the right syntax but what's the right syntax ? Thanks

    Read the article

  • Wordpress Query Compare operator not working?

    - by Liam
    I have the following wordpress query... $args = array('orderby' => 'meta_value_num', 'meta_key' => 'order', 'order' => 'ASC', 'meta_query' => array( array( 'key' => $customkey, 'value' => $customvalue, 'compare' => '=' ), array( 'key' => $customkey1, 'value' => $customvalue1, 'compare' => '=' ), array( 'key' => 'coverageRegion', 'value' => 'national', 'compare' => '=' ), array( 'key' => 'vehicleType', 'value' => 'psv', 'compare' => '!=' ) ) ); I want to return posts where there custom field 'Vechicle Type' is not PSV, The above however returns posts with exactly that, has anybody come across this before? Seems im not the only one neither... http://wordpress.org/support/topic/meta_query-without-key-results-in-compare-of-not-like-not-working

    Read the article

  • C++ Vector at/[] operator speed

    - by sub
    In order to give functions the option to modify the vector I can't do curr = myvec.at( i ); doThis( curr ); doThat( curr ); doStuffWith( curr ); But I have to do: doThis( myvec.at( i ) ); doThat( myvec.at( i ) ); doStuffWith( myvec.at( i ) ); (as the answers of my other question pointed out) I'm going to make a hell lot of calls to myvec.at() then. How fast is it, compared to the first example using a variable to store the result? Is there a different option for me? Can I somehow use pointers? When it's getting serious there will be thousands of calls to myvec.at() per second. So every little performance-eater is important.

    Read the article

  • why no += operator for vectors in stl

    - by Akshay Bhat
    I am curious? What high fundu logic goes behind not implementing: result+=vector1; where both result and vector1 are stl vectors. Note: i know how to implement that bit, but i need to know what logic, the sages who designed STL were using when they chose not to implement this feature?

    Read the article

  • Bizzare Java invalid Assignment Operator Error

    - by Kay
    public class MaxHeap<T extends Comparable<T>> implements Heap<T>{ private T[] heap; private int lastIndex; private static final int defaultInitialCapacity = 25; public void add(T newItem) throws HeapException{ if (lastIndex < Max_Heap){ heap[lastIndex] = newItem; int place = lastIndex; int parent = (place – 1)/2; //ERROR HERE********** while ( (parent >=0) && (heap[place].compareTo(heap[parent])>0)){ T temp = heap[place]; heap[place] = heap[parent]; heap[parent] = temp; place = parent; parent = (place-1)/2; }else { throw new HeapException(“HeapException: Heap full”); } } } Eclipse complains that there is a: "Syntax error on token "Invalid Character", invalid AssignmentOperator" With the red line beneath the '(place-1)' There shouldn't be an error at all since it's just straight-forward arithmetic. Or is it not that simple?

    Read the article

  • Problem with default member functions of class in C++ (constructor, destructor, operator=, copy cons

    - by Narek
    We know that compiler generates some member functions for user-defined class if that member functions are not defined but used, isn't it. So I have this kind of code: class AA { }; void main() { AA a; AA b(a); a = b; } This code works fine. I mean no compiler error. But the following code.... class AA { int member1; int member2; }; But this code gives an run time error, because variable "a" is used without being iniltialized!!! So my question is this: when we instantiate an int, it has a value. So why the default constructer doesn't work and by using those two int numbers initializes variable "a"??

    Read the article

< Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >