Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » C programs » C One Dimensional Array programs

Initialising byte array with decimal, octal and hexadecimal numbers in C



Here, we are going to learn how to declare byte array and initialise array with decimal, octal and hexadecimal numbers in C language.
Submitted by IncludeHelp, on September 06, 2018

byte array in C

In C programming language, an unsigned char type can be used to declare byte array in C programming language. An unsigned char can contain a value from 0 to 255, which is the value of a byte.

In this example, we are declaring 3 arrays – arr1, arr2, and arr3, arr1 is initialising with decimal elements, arr2 is initialising with octal numbers and arr3 is initialising with hexadecimal numbers.

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 





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates



© https://www.includehelp.com (2015-2018), Some rights reserved.