Arithmetic operations on arrays in C

Switch

I am trying to apply arithmetic operations on the values of an array in C. For example, if I want to add a number x to each value of an array, should I add it separately to each value, or instead can I add x to the whole array (so would it automaticaly add it to each value of the array).

Sergey Kalinichenko

if I want to add a number x to each value of an array, should I add it separately to each value

Yes, you need to do it in a loop. C does not provide operators for manipulating the entire array at once.

can I add x to the whole array

An expression that looks like adding an int to an array, e.g. array+x, will compile, but it is a different operation altogether: when an array name is used in an arithmetic operation, it is treated like a pointer to the initial element of the array, so the result of the array+x expression is the same as &array[x] (a pointer to element of array at index x).

Applying += to an array would not compile.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Arithmetic operations on arrays in C

From Dev

Arithmetic operations on arrays of string

From Dev

Arithmetic operations between 2 hash arrays

From Dev

Is it possible to perform arithmetic operations on multidimensional arrays?

From Dev

Arithmetic operations of complex numbers in c

From Dev

Are there any drawbacks using logical instead of integer arrays and values in arithmetic operations?

From Dev

how to profile the number of arithmetic operations in a C/C++ program?

From Dev

Are arithmetic operations on literals in C# evaluated at compile time?

From Dev

Arithmetic operations on vectors

From Dev

Arithmetic operations with fields

From Dev

Vectorizing Arithmetic Operations

From Dev

Arithmetic operations in ember handlebars

From Dev

Arithmetic operations inside templates

From Dev

Arithmetic operations between variables

From Dev

Arithmetic operations in the head of a clause

From Dev

Arithmetic operations in ASM Language

From Dev

arithmetic operations in Alloy

From Dev

Arithmetic operations with fields

From Dev

Vectorizing Arithmetic Operations

From Dev

arithmetic operations between files

From Dev

Arithmetic operations with awk

From Dev

Bitwise and arithmetic operations in swift

From Dev

Arithmetic operations on objects

From Dev

Forth expression arithmetic operations

From Dev

What's the common strategy to optimize c++ arithmetic computation for arrays?

From Dev

pointer arithmetic on arrays

From Dev

Arithmetic within numpy arrays

From Dev

Arithmetic within numpy arrays

From Dev

Pointer Arithmetic using arrays