answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int i;

int a[4]={1,2,3,4};

int *p1,*p2,*p3;

for(i=0;i<4;i++)

{

p1=&a[0];

p2=&a[2];

p3=*p2-*p1;

printf("\n value of p3%d",p3);

}

getch();

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you Add 2 numbers using pointer and array in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you declare a string array and add elements to it in C plus plus?

You cannot add elements to a fixed array in C or C++. If, however, the array is declared as a pointer to an array, you can add elements by allocating a new array, copying/adding elements as needed, reassigning the new array to the pointer, and deallocating the original array.


Why pointer can't be added in computer language C?

You can add a point in C/C++. The legal operations on a pointer are that you can 1.) add a constant, 2.) subtract a constant, and 3.) subtract two pointers that refer to the same array. Anything else is meaningless.


Sum of n numbers using array?

Set sum = 0, then add each of the elements of the array, one by one. Use a for loop to process each element of the array.Set sum = 0, then add each of the elements of the array, one by one. Use a for loop to process each element of the array.Set sum = 0, then add each of the elements of the array, one by one. Use a for loop to process each element of the array.Set sum = 0, then add each of the elements of the array, one by one. Use a for loop to process each element of the array.


What do you mean by function to pointer?

AnswerI take it you are using some version of c,c++,visualC etc etc. One thing that is standard is pointers. A pointer is the address of a memory space that holds information in that specific space. By referencing the pointer in your code, you can print out that specific bit of information that the poiner is actually pointing to. Hope this helps


How do you add two matrices using Linux shell script?

write ashell script to add awo matrix using array.


How do you write a program in java to read ten numbers and print sum of ten integers?

Add the numbers into one variable as you read them in. But if you prefer, you can read the numbers into an array and then use a loop to add the numbers together.


A character Array is defined as char Array 200 150 50 find the address of cell Array 125 80 20?

It is inappropriate and non-portable to consider the address or the relative address of a particular item in an array, because different compiler implementations might be different. Even within the same implementation, there might be issues due to alignment or segmentation. That said, it is perfectly legal and defined to assign a pointer to the address of an element and then perform arithmetic on the pointer, with consistent results. You should not, however, consider the "arithmetic" value of the pointer to have any particular meaning, especially since the concept of "adding one" to such a pointer means to add by the number of bytes in a single element, not (as thought) to add by one. Such "pointer arithmetic" is not advised (or defined ??) when you step beyond the bounds of any one sub-array, again, due to possible alignment issues. Consider your example of an array of char [200][150][50]. You can theoretically think of the memory layout as simply being sequential, with the left-most index varying quickest, and that might work 99.99% of the time. I go for the 100% case and treat the pointer as an opaque object, with no consideration of its internal representation.


When using distributive property if you add the numbers is the answer a product or a sum?

If you simply add numbers the answer is the sum of those numbers.


Add two numbers in pointer in using c plus plus?

int* a = new int(40); int* b = new int(2); int x = *a + *b; // x = 42 delete b; delete a;


How can you add numbers?

Using the additive property (+).


Explain pointer of any data type that requires four bytes?

When a pointer to a data type that requires four bytes is declared, the compiler knows that the target object is four bytes in size. When the program then performs a calculation to offset the pointer, such as to add 3 (for instance) to the pointer, the generated code actually adds 12. This is because the compiler assumes that adding or subtracting numbers to or from a pointer is an attempt to use the pointer in an array context. (Actually, this behavior is defined in the language specification.)The other valid arithmetic manipulation of a pointer is subtraction of two pointers to the same type of object. In this case, again, an internal multiplier of 4 is applied, and the result is an offset that could be used if the first pointer were the base of an array of those objects.The size of the target object could be any value, such as a double which might be 8 bytes. The compiler will do the arithmetic correctly.Also, keep in mind the distinction between the size of the pointer and the size of the object to which the pointer points. This answer assumes the latter.In any case, the programmer must insure that the calculation results in a pointer or offset value that represents an address in the base object array, assuming that the allocated space of that object is correct. Any other result is inconsistent with the defined usage of a pointer, and the result of dereferencing such an inconsistent pointer or offset is undefined by the language specification, and could result in corruption, incorrect behavior, or crash.


How do you make 9 boxes with numbers 1-9 add up to 12 in all directions?

If the boxes are in a 3*3 array, the answer is that you cannot.If the boxes are in a 3*3 array, the answer is that you cannot.If the boxes are in a 3*3 array, the answer is that you cannot.If the boxes are in a 3*3 array, the answer is that you cannot.