format specifier

can anybody tell me how to create a dynamic array for short integers???
is %hd the correct format specifier for short int

1 Like

Is there some difference when you are creating array for int or short int? No. Do you need special modifier? I’m not C/C++ guru, but I’d say no, IMHO %d is ok for short int too.

#include <cstdio>
#include <malloc.h>

#define SIZE 10

int main() {
	short int* arr = (short int*) malloc( SIZE * sizeof(short int) ) ;
	for ( int i = 0; i < SIZE; ++i ) arr[i] = 10*i;
	for ( int i = 0; i < SIZE; ++i ) printf( "%d ", arr[i] ); printf( "\n" );
	return 0;
}
1 Like