#24 C Pointers and Arrays | C Programming For Beginners
Вставка
- Опубліковано 21 лип 2024
- #24 C Pointers and Arrays | C Programming For Beginners
In the last video, we learned about Pointers in C. We learned about working with memory addresses. Now, we will learn to use pointers to work with arrays. We will see examples to access elements using pointers and also to change array elements using pointers. So this video will be very helpful to understand the use of pointers and array with each other much more clearly.
Sign Up to get 50% off with this link: app.programiz.pro/signup?utm_...
This video is a part of our C Programming video series: • #1: Getting Started wi...
~
Resources:
C Online Compiler: www.programiz.com/c-programmi...
Github File: github.com/programiz/c-youtub...
C (title) Tutorial (text-based tutorial): www.programiz.com/c-programmi...
Timestamps:
00:15 - C Pointers and Array
05:15 - Access array elements using pointer
06:43 - Change array elements using pointers
08:40 - Programming Task
09:34 - Quiz
~
Revise your learning using our C App
Download here for Android: bit.ly/3upaInx
Download here for iOS: apple.co/3EZLtNq
Find Programiz elsewhere:
Programiz PRO: programiz.pro
Website: www.programiz.com
Discord: discord.gg/programiz
Facebook: / programiz
Instagram: / _programiz
LinkedIn: / programiz
Twitter: / programiz
#programiz #pointers #array #cprogramming #learnc #cpointers
🔥Finding it Damn Hard to Understand C Programming?
Learn to code-the right way-with interactive lessons, quizzes & challenges. Build a strong programming base; it's IMPORTANT!
Try Programiz PRO for Free: bit.ly/master-c-programming
I love studying with programiz, it's explained so simply :) I'm currently studying for my programming exam that's coming up, so thank you for the free lessons!
ages represent the memory address of the zeroth array element. ie, ages+0 equals &ages[0]. Option D is the correct answer
Amazing, the way you teach is incrible! I got pointers now, I admiti I had some dificult, thank you!
You are making good videos. I am thankful to you for this help. This is avery easy way to learn C language from very beginning.
#include
int main()
{
int arr[5] = {34,12,21,54,48};
int largest = *arr;
int i=0;
for(i=0; i
This video is great,the last programming task makes it perfect.🛐
When I was in college no internet resources were available. To search something simple as function pointers or array pointers we had to read books from Library. It was a tedious process.
A college project could have taken months to complete.
I love how modern education has evolved and become so interesting and simple.
Thanks for your clear explanations :)
Superb! I've liked the explanations for they are well understood.Thanks for making the c programmming knowledge accessible to everyone in need of it.
Plz try to upload the videos faster can't wait to learn any way ur teaching skills are mind blowing
Never thougth I would finally use pointers and make the challenge in this video
Answer is option D mam because the array name represents the address of the first element of the array
Can't wait, so curious about ur next series
Ages represent the first element in the array, which is ages[0]
I don't understand how you make it so easy like this. Thanks a lot
Indeed!
🎉❤❤❤i love the experience here. Keep it up ma'am
Quz answer is option D.
#include
int main()
{
int arr[5] = {5,10,15,20};
int largest = *arr;
int i=0;
for(i=0; i
wouldn't it be better to start iterating the for loop from i=1
No because then you miss the first array element, as arrays start from value 0
amazing teacher😍😍
mam i request you upload the series on daily basis....
nice explanation
good job you guys
U just saved this semester
Thank you
thank u mam
thank you so much ❤❤❤❤🧡🧡🧡🧡💚💚💚💚
Thanks
Wonderful video! i think for the quiz it is D. &ages[0] because its like what was said where if you use just the name of the array it points to the head by deafult
#include
int main() {
// Write C code here
int arr[5] = {34,12,21,54,48};
int largest = *arr;
for(int i = 0; i
can you pls explain the if statement and condition?
thanks
best tutorial for freshers >> beginners
as we are using the %p format specifier we are getting the hexadecimal value if we are using the %d format specifier it is giving different value i am just confused that which is the suitable format specifier for finding the address.
Use %u format spacifier for integer type memory address.
%p is what you are looking for. the hexadecimal value is the acctual memory address where the value is stored.
good video
good good!
Task:
#include
int main() {
int arr[5] = {34, 12, 21, 54, 48};
printf("First element in the array before change: %d
", arr[0]);
int largest = *arr;
*arr = 65;
printf("Fist element in the array after the change: %d
", *arr);
for(int i = 0; i < 5; i++) {
if (largest < *(arr + i) ) {
largest = *(arr + i);
}
}
printf("Largest number of the array: %d
", largest);
return 0;
}
Quiz answer: ages[0] represents the first element of the array, ages[1] represents the second element, and so forth, up to ages[4], which represents the fifth (and last) element of the array.
who has the link to the github
the platform could put OpenGl Course I would Apreciate also, bye
💪🏼
awl hindiya zwina
I did the quiz like this XD:
if(arr[0]>arr[1])
{
largest=arr[0];
if(arr[0]>arr[2])
{
if(arr[0]>arr[3])
{
if(arr[0]>arr[4])
{
printf("Array 0 is the largest!");
}
}
}
}
printf("Array Address: %p
", numbers);
Why are we not using &numbers in this line of code?
isnt 'numbers' supposed to show the value and '&numbers' supposed to show the address?
numbers with brackets mean "the value of an element", numbers without brackets means "address of the first element"
@@fanman2101 thank you
Alloh rozi bolsin
Could anyone tell the difference between
char*array[] = {"hi","hello","bye"}
char ARRAY[] = {"hi","hello","bye"}
?
Second one is wrong, because you need a 2D array whereas you're only declaring a single-dimensional array in the second array
Well the first one is an array of pointers and the second one is a pointer constant pointing to the starting address of that array.
For example
char* arr[]= {
"Ann",
"Ben",
"Dana",
"Elle"
};
you have a array of 4 pointers pointing to the starting address of each string.
The second one ,
char arr[]={"Anna", "Bob","Dana", "Jim};
Is a array , but you can use the array name as a pointer to the starting address of the array.
arr points to the address of first element of the array called arr.
It is the same as &arr[0] or arr +0.
arr+ 1 is the same as &arr[1] , which
points to address of element called "Bob" , arr + 2 same as &arr[2] , which points to the address of element callrd "Dana" and so on through the array.
//char*array[] = {"hi","hello","bye"}
//for the first one by using this we can get the output
#include
int main() {
// Write C code here
char* array[] = {"hi", "hello", "bye"};
for(int i=0; i < 3;++i){
printf("%s
", *(array+i));
}
return 0;
}
//but the second one is a two-dimensional array so you have to use like this
#include
int main() {
// Write C code here
char ARRAY[][20] = {"hi", "hello", "bye"};
for (int i = 0; i < sizeof(ARRAY) / sizeof(ARRAY[0]); ++i) {
printf("%s
", ARRAY[i]);
}
return 0;
}
Option D : &ages[0]
-------------------------------------------------------------------
#include
int main()
{
int arr[5] = {34, 12, 21, 54, 48};
int largest = *arr;
int i;
for(i=0; i
#include
int main() {
int array[5] = {34, 12, 21, 54, 48};
int largest = *array;
for (int i = 0; i < 5; ++i) {
if (largest < *(array + i)) {
largest = *(array + i);
}
else {
printf("%d
", *(array + i));
}
}
printf("Largest element of array is %d", largest);
return 0;
}
d.&ages[0]
for memory addresses, I am supposed to get 0x(some set of numbers and upper/lowercase letters), but when I run the code at 1:53, I am just getting numbers and a repeated set of uppercase letters
Ex:
1 = 000000452BEFF938
3 = 000000452BEFF93C
5 = 000000452BEFF940
7 = 000000452BEFF944
9 = 000000452BEFF948
does anyone know why this is?
well that was her system basically a cloud system and this is your system both will have a different memory location If I do it I will get some other output anyway be happy that you got hexadecimal values
What platform are you running on
/*
Create a program to find the largest element of an array using pointers.
int arr[] = {34, 12, 21, 54, 48);
• Assign the first element of the array to a largest variable using pointer
int largest = *arr
• Run a for loop to access each element of the array.
• Compare largest with each array element using pointer
largest < *(arr + i)
• If the largest variable is smaller than a element, assign the array value to largest
largest = *(arr + i)
*/
printf("
-- Programming Task --
");
int arr[] = { 34, 12, 21, 54, 48 };
int largest = *arr;
for (int i = 0; i < 5; i++) {
if (largest < *(arr + i))
largest = *(arr + i);
}
printf("Largest element is %d", largest);
Answer is D...
D
Q. In an array, int ages[5], what does ages represent?
A. ages[4]
B. ages[0]
C. &ages[4]
D. &ages[0]
I have to watch video first.
ages[0]
ages is the base address of the array called ages. The name ages without a subscript always means &ages[0] or ages + 0 .
It is the starting address of the array in memory, the address of the first element of the array.
Option D
B. ages[0]
d
Quiz answer is B. ages[0]
Hello
0 = gyro
why]
The answer is D.
how
Answer =
/*
Program to find largest elemnt of an array using pointers.
Instructions:
Assign first element of array to a largest variable using pointer,
int largest = *arr;
run a loop to read each element of the array, compare largest with each array element using pointer.
largest < *(arr + i);
if largest variable < element assign the array value to largest variable.
largest = *(arr + i);
*/
#include
int main()
{
int arr[5] = {34, 12, 21, 54, 48};
int i;
int largest = *arr;
for(i = 0; i < 5; i++)
{
if(largest < *(arr + i))
{
largest = *(arr + i);
}
}
printf("Largest value in array = %d", largest);
return 0;
}
int numbers[5] = {34, 12, 21, 54, 48};
int* largestPointer = numbers;
for(int i = 0; i < 5; i++) {
int* currentPtr = numbers + i;
if(*currentPtr > *largestPointer) {
largestPointer = currentPtr;
}
}
printf("%d", *largestPointer);
is that a solution
#include
int main (){
int arr[] = {32, 12, 21, 54, 48};
int largest = *arr;
for(int i = 0; i < 5; i++){
if(largest < *(arr+i)){
largest = *(arr + i);
}
}
printf("Largest element of array is %i.
", largest);
return 0;
}
Quiz 'D'
#include
#include
int main(){
int arr[] = {34,12,21,54,48};
int largest = *arr;
for(int i = 0; i < 5; i++){
if (largest < *(arr+i)){
largest = *(arr+i);
}
}
printf("Largest number is %d",largest);
return 0;
}
Free Palestine 🇵🇸🫀
wash your hair pleaseeeeee.
😂😂dfkm
What's wrong with her hair? Stop being racist! If you didn't like it, don't freaking watch her videos, that's it...
Bruh?
Nothings wrong with her hair, you wash your eyes :D
#include
#include
#include
#include
#include
int main() {
int arr[] = {34, 12, 21, 54, 48};
int largest = *arr;
for(int i = 0; i < 5; i++) {
if (largest < *(arr + i)) {
largest = *(arr + i);
}
}
printf("%d", largest);
return 0;
}
Programiz Task
#include
int main(void)
{
int numbers[5] = {34, 12, 21, 54, 48};
int largest = *numbers;
for(int i = 0; i < 5; i++)
{
if(*(numbers + i) > largest)
{
largest = *(numbers + i);
}
}
printf("Largest Element: %d", *(&largest)); //lol
return (0);
}
#include
int main() {
int arr[] = { 34 , 12 , 21 , 54 , 48,};
printf(" Find the largest value of this array {34 , 12 , 21 , 54 , 48} :
");
int largest = *arr;
for(int i=0 ; i < 5 ; ++i)
{
if ( largest < *(arr + i)){
largest = *(arr+i);
}
}
printf("The largest value is : %d" , largest);
return 0;
}
#include
int main() {
int arr[5] = {34, 12, 21, 54, 48};
int i;
int largest = *arr;
for (i = 0; i < 5; i++)
if (largest < *arr + i)
largest = *(arr + i);
printf("the largest variable is %d
", largest);
return 0;
}
#include
int main() {
int arr[]={34,12,21,54,48};
int largest = *arr;
for(int i=0;i
#include
/* Create a program to find the largest element of Array
using pointer */
int main()
{
int arr[5] = {2, 4, 23, 5, 7};
int large_element = *arr;
for (int i = 0; i < 5; i++)
{
if (*(arr + i) > large_element)
{
large_element = *(arr + i);
}
else
{
continue;
}
}
printf("
largerst element of array: %d", large_element);
return 0;
}
#include
#include
int stdsize = 20;
int main() {
int numbers[5];
int sizeOfNum = sizeof(numbers)/sizeof(*numbers);
for(int i = 0; i < sizeOfNum; i++){
printf("
Enter an integer value: ");
scanf("%d", &numbers[i]);
}
printf("The values of the array 'numbers' is: ");
for(int i = 0; i < sizeOfNum; i++){
printf("%d ", numbers[i]);
}
int largest = *numbers;
printf("
The supposed largest value is: %d", largest);
for(int i = 0; i < sizeOfNum; i++){
if(largest < *(numbers+i)){
largest = *(numbers+i);
}
}
printf("
The actual largest value is: %d", largest);
return 0;
}
#include
int main() {
int i,size;
printf("Enter the size of array : ");
scanf("%d", &size);
int array[size];
printf("Input Any %d elements :- ",size);
for (i = 0; i < size; i++ )
{ printf ("
array[%d] = ", i);
scanf (" %d", &array[i]);
}
int largest = *array;
for (int i = 0; i < 5; ++i) {
if (largest < *(array + i)) {
largest = *(array + i);
}
}
printf("Largest element of array is %d", largest);
return 0;
}
#include
int main() {
int arr[5] = { 34, 12, 21, 54, 48 };
for (int i = 0; i < 5; i++) {
if (*arr < *(arr + i)) {
*arr = *(arr + i);
}
}
printf("%d", *arr);
return 0;
}
#include
void* findProduct (int* num1, int* num2, int* productOF);
int main () {
int number1 = 9;
int number2 = 13;
int products;
int* result = findProduct(&number1, &number2, &products);
printf("The product is %d", *result);
return 0;
}
void* findProduct (int* num1, int* num2, int* productOF){
int product = *num1 * *num2;
*productOF = product;
return productOF;
}
D
#include
int main() {
int arr[5] = {34,12,21,54,48};
int largest = *arr;
for(int i=0;i
#include
int main()
{
int arr[5] = {34,12,21,54,48};
int* ptr , largest ;
ptr = &arr[0];
largest = *ptr;
for (int i = 0 ; i < 5 ; ++i){
if (*(ptr + i) > largest){
largest = *(ptr + i);
}
}
printf("The largest value is %d", largest);
return 0;
}
#include
int main() {
int numbers [6] = {23,45,37,54,81,63};
int largest= *numbers;
for(int i =0; i < 6; ++i) {
if(largest < *(numbers+i)){
largest = *(numbers+i);}
}
printf("largest element is %d", largest);
return 0;
}
#include
int main()
{
int i;
int ary[5] = {34, 12, 21, 54, 48};
int largest = *ary;
for(int i = 0; i < 5;i++){
printf("%d
", ary[i]);
if(largest < *(ary + i)){
largest = *(ary + i);
}
}
printf("the largest value is %d
", largest);
return 0;
}
#include
int main() {
int arr[] = {34, 12, 21, 54, 48};
int largest = *arr; // largest = arr[0]
for (int i = 0; i < 5; ++i) {
if (largest < *(arr + i)) {
largest = *(arr + i);
}
}
printf("The Largest value of an Array is: %d", largest);
return 0;
}
#include
int main(){
int arr[] = {34,12,21,54,48};
int largest = *arr;
for(int i = 0; i < 5; ++i){
if (largest < *(arr + i)){
largest = *(arr + i);
}
}
printf("The largest number of array is : %d", largest);
return 0;
}
#include
int main() {
int arr[5] = {34,12,21,54,48};
int largest = *arr;
for(int i=0; i
#include
int main() {
int arr[5] = {34, 12, 21, 54, 48};
int largest = *arr;
for(int i; i < 5; i++) {
if(largest < *(arr + i)) {
largest = *(arr + i);
}
else {
printf("%d
", *(arr + i));
}
}
printf("Largest number is %d", largest);
return 0;
}
#include
int main() {
int arr[] = {34, 12, 21, 54, 48};
int largest = *arr;
for(int i=1; i