Created
August 24, 2019 12:43
-
-
Save itsNikolay/6d859287f8a579592aa37f0149dec771 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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