null pointer code example

Example 1: array null pointer java

class teste {
  public static void main(String[] args) {
  	// U will most likekly get a null pointer 
  	//if u dont inicialize the arr like that
	int[] arr = new int[ARRAY_SIZE]; // Correct
  	int[] arr; //incorrect and might have nullpointer
  }
	
}

Example 2: SET TO NULL pointer c++

*ptr=NULL; /*or*/ *ptr=0;

Example 3: null pointer exception method

public class MainClass {

    public static void main(String[] args) {
        anotherTest();
        test();
    }
    public static void test() {
        System.out.println("Printed from the test method.");
    }
    public static void anotherTest() {
        System.out.println("Printed from the anotherTest method.");
    }
}

Tags:

Misc Example