Q:

Initialising byte array with Decimal, Octal and Hexadecimal numbers in C

0

Initialising byte array with Decimal, Octal and Hexadecimal numbers in C

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Example:

#include <stdio.h>

int main()
{
	//declaring array, initialising with decimal values	
	unsigned char arr1[]={10, 20, 30, 40, 50};
	//declaring array, initialising with octal values	
	unsigned char arr2[]={010, 077, 023, 045, 057};		
	//declaring array, initialising with hexadecimal values	
	unsigned char arr3[]={0x10, 0xAA, 0x67, 0xA1, 0xFF};	
	int i;
	
	//printing the numbers
	printf("arr1...\n");
	for(i=0; i<5; i++)
		printf("%d ",arr1[i]);
	printf("\n");

	//printing the numbers
	printf("arr2...\n");
	for(i=0; i<5; i++)
		printf("%o ",arr2[i]);
	printf("\n");
	
	//printing the numbers
	printf("arr3...\n");
	for(i=0; i<5; i++)
		printf("%X ",arr3[i]);	
	printf("\n");
	
	return 0;	
}

Output

arr1...
10 20 30 40 50 
arr2...
10 77 23 45 57 
arr3...
10 AA 67 A1 FF 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

One Dimensional Array Programs / Examples in C programming language

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C program to count Array elements by using sizeof(... >>