Hi, I need the coding to add 10 numbers using function and array and by not using pointers.whethet it is possible to add the numbers without using pointers.i need a clear idea about array and functions.If any one knows plaz help me. -Sakthi
Simple Code: int add(int arr[10]) { int res = 0; for(int i=0;i<10;i++) res += arr[i]; return res; } int main() { int arr[10] = {1,2,3,4,5,6,7,8,9,10}; int x = add(arr); return 0; }
Hi, I need the coding without specifying the array size directly.that is u gave the array size as 10 na,for that we have to get the number from the user. -Sakthi
No problem juts use the pointer instead of aaray and use malloc to allocate the pointer and use like an array.
Hi, Thanks for replying the previous program.I need a C coding for another program for finding the inverse of the matrix,sorting of the matrix,without using the pointers only by using the array.Please help me. -Sakthi
hi i have one doubt regarding Strings.for reading the input from the keyboard we are using & for all other data type xcept string.can i know the reason y we are not using & for string in the scanf function. Sakthi
Scanf needs a pointer to the variable. Consequently, the "address-of" operator (&) is applied to the name of the variable. A C-string is not a single "thing", but a collection of such things (chars). The name of the array is treated as a pointer to its first element. Since it's already a pointer, the address-of operator is not required. As Shabbir mentions, please put separate questions in separate threads. It's a matter of organization and promotes searchability.
hi i meant the & as the address operator.my question s that for all other data type for reading the input we are using &(ampersan) in the scanf function,but while we are reading strings we are not using &.can i know the reason for that eg; scanf("%s",a); Sakthi
n C, a string is stored as a null-terminated char array. This means that after the last truly usable char there is a null, hex 00, which is represented in C by '\0'. The subscripts used for the array start with zero (0). The following line declares a char array called str. C provides fifteen consecutive bytes of memory. N.B. Only the first fourteen bytes are usable for character storage, because one must be used for the string-terminating null. char str[15]; The following is a representation of what would be in RAM, if the string "Hello, world!" is stored in this array. Characters: H e l l o , w o r l d ! Hex values: 48 65 6C 6C 6F 2C 20 77 6F 71 6C 64 21 00 Subscripts: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 The name of the array is treated as a pointer to the array. The subscript serves as the offset into the array, i.e., the number of bytes from the starting memory location of the array. Thus, both of the following will save the address of the 0th character in the pointer variable ptr. ptr = str; ptr = &str[0]; As because the name of the array is treated as a pointer you do not need to use the address-of operator because the pointer is itself an address. I hope I was able to help you out.
hi dawei i post the thread b4 3 days.i think pradeep asked me that what i m going to xplain.thats y i post the thread once again.after posting that i got the reply.sterday itself i read that.