Skip to content

Instantly share code, notes, and snippets.

@itsNikolay
Created August 24, 2019 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsNikolay/6d859287f8a579592aa37f0149dec771 to your computer and use it in GitHub Desktop.
Save itsNikolay/6d859287f8a579592aa37f0149dec771 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int *initArray(int n) {
int i;
int *array;
array = malloc(n * sizeof(*array));
/* you should always check malloc success */
if (array == NULL)
return NULL;
for (i = 0 ; i < n ; i++) {
array[i] = i * 2;
}
return array;
}
int main() { /* main should return int */
int i, n = 5;
int *array;
array = initArray(n);
/* if null is returned,
* you can't dereference the pointer */
if (array == NULL)
return -1;
printf("Here is the array: ");
for(i = 0 ; i < n ; i++) {
printf("%d ", array[i]);
}
/* you sould free the malloced pointer or
* you will have a memory leak */
free(array);
printf("\n\n");
return 0;
}
set nocompatible
filetype off
set encoding=utf-8
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'Shougo/deoplete.nvim'
Plugin 'roxma/nvim-yarp'
Plugin 'roxma/vim-hug-neovim-rpc'
call vundle#end()
filetype plugin indent on
" bug in `longest`
set completeopt=longest,menu,preview
let g:deoplete#enable_at_startup = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment