Today's Question:  What does your personal desk look like?        GIVE A SHOUT

SEARCH KEYWORD -- int



  C++/CLR int to System::String^

In C++/CLR (for Microsoft), sometimes we need to convert int to System::String type or vice versa. The simple way is :From System::String^ to int int num= int::Parse(str); // System::String^ to int From int to System::String^ System::String^ str = num.ToString(); // int to System::String^For all the other data types, similar ways can be adopted....

   C++,CLR,Microsoft,System::String,Convert,int     2011-12-15 12:47:22

  C/C++ Pointer Declaration Syntax – It makes sense!

I never really liked the way pointers are declared in C/C++: int *a, *b, *c; // a, b and c are pointers to int The reason is that I am used to reading variable declarations as MyType myVar1, myVar2, myVar3; and I always read “int*” as the type “integer pointer”. I therefore wanted the following int* a, b, c; // a is a pointer to int, b and c are ints to mean that a, b and c all were of type int*, i.e. pointers to int. and I therefore found it slightly a...

   C,Pointer,Declaration,Attempt     2012-02-22 05:43:58

  Implementation of +,-,*,/ with bitwise operator

There is a question asked on Stackoverflow : Divide a number by 3 without using *,/,+,-,% operators. This question is an Oracle interview question. Some people give excellent answers. You can go there and take a look. Usually we need to use bitwise operators to do this kind of implementations. Here I want to show you ways to implement +,-,*,/ with bitwise operators. A bitwise operation operates on one or more bit patterns or binary numerals at the level of their individual bits. It is a fast, pr...

   Bitwise operator,Shift,Add,Subtract,Multiplication,Division     2012-08-05 01:52:47

  template function in class in C++

We can define template function in a class, but one thing we should pay attention to is that the member function template definition (in addition to the declaration) should be in the header file, not the cpp, though it does not have to be in the body of the class declaration itself.Example //Sorter.h#pragma onceclass Sorter{public:    Sorter(void);    ~Sorter(void);    template <class type> static void qsort(type arr[],int start,int end);};templ...

   C++,template function,class,definition,d     2011-08-07 09:39:56

  How many bytes a boolean value takes in Java?

Have you ever wondered how many bytes a boolean value takes in Java? One byte, this might be the answer comes out of your mind right away. But is it? Let's dig in more. Per Oracle documentation on boolean value definition, there is below statement: boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defin...

   JAVA,INTERVIEW,SIZE,BOOLEAN     2020-02-29 02:49:18

  3 ways to remove duplicates in List

Frequently, we may have an ArrayList which stores many values, and we need to process the ArrayList and get what are the distinct values in the list, or we may want to count occurrence of each value in the ArrayList. We can remove the duplicates in a few ways. Here we propose 3 methods :     public static void main(String[] args){        //SuperClass sub=new SubClass();                String[...

   Java,List,Duplicate,Clear     2012-09-03 09:44:32

  One good way to use optional parameter in function

In GoLang, it doesn't support method overloading like in Java, hence sometimes it would be a headache to create functions to construct new structs with different parameters.  Normally, we would construct the new function as below when want to let others create a new struct instance with explicit function call. type Queue struct { Name string } func NewQueue(name string) *Queue { return &Queue{name} } But with the scope and complexity of the struct increases, there might be more prope...

   OPTION PATTERN,VARIADIC FUNCTION,OPTIONAL PARAMETER     2020-09-18 21:45:29

  Be careful about nil check on interface in GoLang

nil check is frequently seen in GoLang code especially for error check since GoLang's special error handling convention. In most cases, nil check is straight forward, but in interface case, it's a bit different and special care needs to be taken. Take a look at below code snippet and guess what the output will be. package main import ( "bytes" "fmt" "io" ) func check(w io.Writer) { if w != nil { fmt.Println("w is not nil") } fmt.Printf("w is %+v\n", w) } func main() { var b *bytes.B...

   INTERFACE,GOLANG,NIL CHECK,NIL TYPE,NIL VALUE     2019-04-06 07:47:07

  Comparable and comparator in Java

Comparable and comparator are two similar interfaces used to compare objects in Java. When we want to sort a list of objects such as Employee or User etc, we may need to implement these interfaces to make them comparable as we want. However, there are some differences between comparable and comparator interface.ComparableA comparable object is capable of comparing itself with another object. The class itself must implements the java.lang.Comparable interface in order to be able to compare its in...

   Java,Comparable,Comparator,Sort     2012-07-04 12:06:15

  Smuggling data in pointers

While reading up on The ABA Problem I came across a fantastic hack.  The ABA problem, in a nutshell, results from the inability to atomically access both a pointer and a "marked" bit at the same time (read the wikipedia page).  One fun, but very hackish solution is to "smuggle" data in a pointer.  Example:#include "stdio.h"void * smuggle(void * ptr, int value){  return (void *)( (long long)ptr | (value & 3) );}int recoverData(void * ptr){  return (long long)ptr &...

   C,Pointer,Bit,Data,Atomic,Smuggle     2011-11-14 08:15:59