C,C++/JAVA/BASH/ASM ARENA

वह प्रदीप जो दीख रहा है झिलमिल दूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है चिन्गारी बन गयी लहू की बून्द गिरी जो पग से चमक रहे पीछे मुड देखो चरण-चिनह जगमग से बाकी होश तभी तक, जब तक जलता तूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है अपनी हड्डी की मशाल से हृदय चीरते तम का, सारी रात चले तुम दुख झेलते कुलिश का। एक खेय है शेष, किसी विध पार उसे कर जाओ; वह देखो, उस पार चमकता है मन्दिर प्रियतम का। आकर इतना पास फिरे, वह सच्चा शूर नहीं है; थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है। दिशा दीप्त हो उठी प्राप्त कर पुण्य-प्रकाश तुम्हारा, लिखा जा चुका अनल-अक्षरों में इतिहास तुम्हारा। जिस मिट्टी ने लहू पिया, वह फूल खिलाएगी ही, अम्बर पर घन बन छाएगा ही उच्छ्वास तुम्हारा। और अधिक ले जाँच, देवता इतन क्रूर नहीं है। थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है।

Got amazed by the exppression &(((struct st *) 0) ->member_st). But finally found this is valid and C has similar implementation for ‘offsetof’ September 16, 2013

Filed under: C,C Library,C++ Programs,Coding,Compiler,Computers — whoami @ 20:23

Some day back i was going through some library code in C and found expression like

 &(((some_struct_type *) 0) -> some_element_of_some_struct_type);

And started wondering what will happen to access an element located at NULL. Thought something is wrong with the code then one of my senior suggested suggested this is Ok and then found lot of information on the web. Also the same feature is available in C as MACRO offsetof.

1. Stackoverflow

2. Stackoverflow

3. C wiki

4. C examples

 

Conclusion:

* The expression ((some_struct_type *) 0) -> some_element_of_some_struct_type is invalid/undefined because we are trying to access element of some structure which is not correctly located at defined address. But the expression prefix with & becomes valid because the whole expression of getting address of member element of struct (assumed to be located at NULL) is calculated at compile time and hence dereferencing is avoided.

 

Advertisements
 

Execute .jar file on Double Click -Linux March 2, 2010

Filed under: JAVA,LINUX,Top Coder — whoami @ 09:08
Tags: , ,

Read this link.

Actually u have to change 2 things- in properties of .jar file-
1. set the permission to run it as a program
2.then open with – use custom command , there find the location of jexec and press open.
Now ur file directly open with this jexec command after pressing double click…..
I am using it run The Editors for TopCoder
Thanks

 

Java Errors October 26, 2009

Filed under: C,Coding,JAVA — whoami @ 08:17
Tags:

If following error u r getting , then :
Main.java:12: cannot find symbol
symbol : constructor BufferedReader(java.io.InputStream)
location: class java.io.BufferedReader
BufferedReader in = new BufferedReader(System.in);
^
1 error
—————————————-
Sol:
[Do this]
InputStreamReader br = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(br);

 

JDBC Programming October 9, 2009

Filed under: JAVA,JDBC — whoami @ 18:08
Tags:
 

A Brief History of Java and JDBC

Filed under: JAVA,ORACLE-SQL — whoami @ 17:02
 

TO DO List : September 24, 2009

Filed under: C,C++ Programs,Coding,JAVA — whoami @ 18:19
Tags:

SPECIAL NUMBERS(OPC practise contest Shaastra 2009)

A number is said to be special if the number of divisors it has is equal to a power of 2. For example, 6 is a special number since it has four divisors 1,2,3 and 6. A very special number is a special number whose sum of divisors is also equal to a power of 2. Given a number, print the smallest very special number that is greater than or equal to the given number.

Input:
First line of the input contains a number t, the number of test cases to follow. The next t lines each contain a number N.

Output:
Print on a new line for each test case,the smallest very special number greater than or equal to N.

Constraints:
t<5000
N<=2*10^14

Sample Input
2
23
20000000000

Sample Output
31
22545653781

Time limit: 1 second
Memory limit: 64 MB

 

Palindrome August 30, 2009

Filed under: JAVA — whoami @ 15:39
Tags:

import java.io.*;
class palim
{
 public static void main(String args[]) throws IOException
 {
 System.out.println("Enter The Number");
 DataInputStream in=new DataInputStream(System.in);
 int num=Integer.parseInt(in.readLine());
 int n=0,rem=0,old=num;
 while(num>0){
 rem=num%10;
 num=num/10;
 n=n*10+rem;
 }

 if(n==old)
 System.out.println("The Given number is Palindrme");
 else
 System.out.println("Given number is not palindrome");

 }//end of main

}