Suppose you have a vector array at C++ and you want to extract a sub-vector given some range. There is a simple illustration one of the possible way to do.
[gist] <script src=”https://gist.github.com/erogol/8631128.js”></script> [/gist]
yield function is one of the good stuff in the Ruby that gives different kind of code reuse logic to your code. It just like lambda in Scheme and Lips. when yield is called in a function it cuts the execution of its container function and pass the execution time to the do-end block then when the execution ends with the end keyword, it continues the execution from the last point.
Here is an example code that uses yield function.
def around_staff eren = 20 puts "first step" yield(eren) puts "last step" end def do_something around_staff do |eren| puts "I did something around"+ eren.to_s end end do_something
def initialize _age
@age = _age
def <=> other
self.age <=> other.age
e1 = Eren.new(10)
e2 = Eren.new(11)
e3 = Eren.new(2)
d = [e1,e2,e3].sort!
d.each do |x|
This example code illustrates the basic implementation of IPC mechanism that is provided by POSIX API.
int main(int argc, char **argv)
const int size = 5096; // in bytes
//create shared mem.
segment_id = shmget(IPC_PRIVATE, size, S_IRUSR|S_IWUSR);
//attach the shared mem. to the process in Write Read mode.(0 argument)
shared_mem = (char * )shmat(segment_id, NULL, 0);
//write the data to the shared memory.
sprintf(shared_mem, "This is the shared memory example coded by Eren Golge. Regards!!");
//read the data from
printf("*%s n", shared_mem );
//detach the segment from process
//delete the shared mem. segment form memory
shmctl(segment_id, IPC_RMID, NULL);
printf("End of code");