How can I resolve this issue?

I just want to create a triangle, but it keeps crashing.

Error:Exception thrown at 0x00000000 in OpenGL.exe: 0xC0000005: Access violation executing location 0x00000000.


#include <GLFW/glfw3.h>


int main(void)
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
        return -1;

    /* Make the window's context current */

    static const GLfloat g_vertex_buffer_data[] = {
    -1.0f, -1.0f, 0.0f,
     1.0f, -1.0f, 0.0f,
     0.0f,  1.0f, 0.0f,

    GLuint VertexArrayID;
    glGenVertexArrays(1, &VertexArrayID);

    GLuint vertexbuffer;

    // Generate 1 buffer, put the resulting identifier in vertexbuffer
    glGenBuffers(1, &vertexbuffer);

    // The following commands will talk about our 'vertexbuffer' buffer
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);

    // Give our vertices to OpenGL.
    glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
        /* Render here */

        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
            0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
            3,                  // size
            GL_FLOAT,           // type
            GL_FALSE,           // normalized?
            0,                  // stride
            (void*)0            // array buffer offset
        // Draw the triangle !
        glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle

        /* Swap front and back buffers */

        /* Poll for and process events */

    return 0;

Please review the Forum Posting Guidelines for suggestions on what to include in a post so that it is more likely to get you helpful answers.

With the information you have provided it is difficult to say more than “your code has a bug”. Try using a debugger to determine where exactly your code crashes.
It looks like your code is attempting to dereference a null pointer. Purely guessing I suspect your problem could be related to initializing OpenGL function pointers, see Getting Functions on the wiki.