answersLogoWhite

0

What are subscripts in c language?

Updated: 8/11/2023
User Avatar

Wiki User

12y ago

Best Answer

Subscripts are used when accessing arrays. An array is a contiguous block of memory containing two or more elements of the same type. Since each element is the same length, it is trivial to work out the offset address of one element relative to another using a zero-based index. For any type T, the type T[n] is an array of Ts with indices in the range 0 to n-1. We can also create arrays at runtime by allocating sufficient memory on the heap for the given type:

void f(int n) {

if (n<1) return; // cannot allocate 0 elements!

int* ptr = malloc (n * sizeof(int)); // allocate memory for n integers

if (ptr!=0) return; // ensure memory was allocated!

ptr[0] = 42; // use subscript operator to assign a value to the first element

// assign to other elements...

// use array...

free (ptr); // release memory as soon as we're finished with it

}

User Avatar

Wiki User

7y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

In c language , subscript is used to allocate memory location using index in array

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

Given an array x, the subscript x[n] returns a reference to the n-1th element of x.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are subscripts in c language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Explain specifically what the subscripts mean in the molecule formula C6H12O6?

explain specifically what the subscripts mean in the molecule formula c 6 h 12 o 6


Do any languages have array subscripts beginning with 1?

Yes, PHP and C both do.


What is the total number of atoms of carbon in the formula K3FeCN6?

In chemical formulas, carbon atoms are denoted with the symbol C. Subscripts and superscripts denote the number of carbons. Since there is only one C and no subscripts or superscripts, the compound stated contains only one carbon atom.


Why c language has name c why not a?

C-language was derived from B-language.


What is previous language of c language?

language before c language is pascal


What is C language what does it do?

C Language is First Step of Programming Language, Help for C Language you are show the correct answer


Array subscripts are always a large numbers b characters c negative values d integers?

d integers


What is the topNet class that everything is derived from in c?

C language: int (but C is NOT a .net language) C# language: object or System.Object


What is versions of c language?

versions of c language?


What do you mean by c language?

C is a programming language.


Is there a c in the greek language?

Yes, there is a symbol in the Greek alphabet that represents the /k/ sound, called “kappa.” However, the letter “c” like in the English alphabet does not exist in the Greek language.


Is c a dependent language?

C is a independent language