Pointers (Program 1) | Sum of Array Elements using Pointers

preview_player
Показать описание
C Programming: Pointers Program in C Programming.
Topic discussed:
1) C program to calculate the sum of elements of an array using the pointers.

Music:
Axol x Alex Skrindo - You [NCS Release]

#CProgrammingByNeso #CProgramming #Pointers #PointersProgram #PointersInC
Рекомендации по теме
Комментарии
Автор

One other important method:
for(int i = 0; i<n; i++) sum+= *(arr+i);

akshitarora
Автор

Its informative and i would like to congratulate u for the efforts u put forth...

akhils
Автор

Straight forward clean understandable teaching no bullsh*t.

jaybhoyar
Автор

Very nice! Thanks for helpful video! <3

sodge
Автор

Traditional method:
for(int i = 0; i < sizeof(a)/sizeof(a[0]); sum += a[i], i++);

Using pointers:
for(int *p = &a[0]; p <= &a[sizeof(a)/sizeof(a[0])-1]; sum += *p, p++);

sdk
Автор

Consider an integer array of N elements. Find out the sum of first N/2 elements and sum of last N/2 elements using only one pointer variable (no other loop variables allowed) and only one loop construct.

anonymouskiot
Автор

alternate code with sizeof(), to just refresh the concept
#include <stdio.h>
#include <stdlib.h>
int main(){
int a[] = {11, 22, 36, 5, 2};
int *p = &a[0];
int i, sum=0;

sum+=*(p+i);
}
printf("%d", sum);

}

mohammedshahbaazshareef
Автор

I now clearly understand the concept of pointers, but I have difficulty in understanding their case of use? For this example at least I would use the normal i to iterate the array and perform the same result?

randompotato
Автор

Interesting Video - can you use #define SIZE &a[4] and then use SIZE in the for loop?

rajcodes
Автор

Sir why your not uploading ece gate lectures

Udaykumar-edqj
Автор

Sir please try to complete network theory playlist .
Because its basic sir for electrical and electronics

NESO- sir can you please tell me when network theory playlist will again continue

aniketyagik
Автор

Sir please make video about double pointer...🙏🙏🙏

surojitkarmakar
Автор

sir why here we are assigning the value of p to second part of for loop after incrementing p. shouldn't we first assign the value of p and then increment its value.

nikhilanand
Автор

Can u send the c program code of below program sir??

anonymouskiot
Автор

2:31
//Will the below program suites for the sum of an array using pointers..? if not correct me plz...

#include <stdio.h>
#include <conio.h>
int main()
{
int a[] = {11, 22, 36, 5, 2};
int n = sizeof(a)/sizeof(a[0]);
int *p = &a[0], i, s=0;
for(i=0;i<n;++i)
{
s = s + *(p+i);
}
printf("Sum = %d\n", s);
}

balajigv
Автор

Can't u tell with variable length arrays

kollururamakrishna
Автор

I Think that it would be better to use "++p" instead of "p++" because in the last iteration "p" will points to &a[5] which is not belongs to the array, thus making segfault errors possible

accessdenied
Автор

but my compiler show answer is sum is 87

vishvachavan
Автор

1:00 As of today most machine are little endian. But even though what if the machine run on Big Endian?? then isn't &a[0] will always be > &a[4]

sane
Автор

#include<stdio.h>

int main()
{
int a[7]={23, 41, 19, 18, 98, 40, 10}, r=0, *result=&r;
for(int i =0; i<7; i++)
{
*result = *result + a[i];
}
printf("sum of element %d", *result);
}

Can we do in this way also?

ritikshrivastava