#25 C Pointers and Functions | C Programming For Beginners

preview_player
Показать описание
#25 C Pointers and Functions | C Programming For Beginners

In this video, we will learn to use Pointers and Functions together in C Programming. We'll learn to pass addresses and pointers as arguments to functions with the help of examples.

In C programming, it is also possible to pass addresses as arguments to functions. Let's learn all these in this video. To accept these addresses in the function definition, we can use pointers. It's because pointers are used to store addresses.

~
Resources:

Timestamps:

00:18 - C Pointes and Functions
02:28 - Find the square of a number
04:39 - Return Pointers from a Function
06:21 - Add two numbers
08:50 - Programming Task
09:44 - Quiz
~

Revise your learning using our C App

Find Programiz elsewhere:

#programiz #pointers #functions #pointersexample #functionexamples #cprogramming #learnc
Рекомендации по теме
Комментарии
Автор

🔥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!

programizstudios
Автор

i love the fact that u use English as the medium of communication and your soo good at explaining but i can see that very clearly when executing those codes or functions

deogracious
Автор

#include <stdio.h>

int* Multiplication(int* num1, int* num2, int* result) {
*result = *num1 * *num2;

return result;
}

int main() {

int number1 = 13;
int number2 = 9;
int thirdPointer;

int* result = Multiplication(&number1, &number2, &thirdPointer);

printf("Multiplication is %d", *result);

return 0;
}

countrysideshowyaigrock
Автор

It made me bit confusing at the beginning, but by the last example of adding two numbers is made me clear of this topic. Thank you very much Programiz!

ntnmfbu
Автор

Short, simple and easy to understand. ❤

Noir
Автор

Why do you need to make the function return a pointer and not simply void? If you pass three pointers to it you can just say *sum = *num1 * num2;
then you call the function in main after you create your variables and print the sum in a printf like below:
void multiply(int* num1, int* num2, int* sum);
int main()
{
int num1 = 13;
int num2 = 9;
int sum;
multiply(&num1, &num2, &sum);
printf("sum = %d", sum);
return 0;
}
void multiply(int* num1, int* num2, int* sum){
*sum = *num1 * *num2;
}

SeventeenDistinctRacoons
Автор

Q. What type of value does the following function return?

double* func(int* a) {
...
}

A. Integer value
B. Address of integer variable
C. Double value
D. Address of double variable

programizstudios
Автор

wonderful video! im so glad to have some of this information and clarification, pointers are so unusual for me right now, here is the task:
#include <stdio.h>

int* multNumbers(int* num1, int* num2, int* sum){

*sum = *num1 * *num2;

return sum;
}

int main() {
// Write C code here
int number1 = 13;
int number2 = 9;
int sum;

int* result = multNumbers(&number1, &number2, &sum);
printf("Result is: %d", *result);

return 0;
}
and for the quiz i believe it is D. Address of a double variable, i say this because the return type shown is 'double*'

thomasguerra
Автор

Programiz Task


// Online C compiler to run C program online
#include <stdio.h>
#include <math.h>

int* multiply(int* num1, int* num2, int* product)
{
*product = *num1 * *num2;

return product;
}

int main() {
// Write C code here

int num1 = 13;

int num2 = 9;

int product;
multiply(&num1, &num2, &product);


printf("Product is: %d", product);

return 0;
}

aguywithoutaname
Автор

My compiler gives a warning error if the return on the function is not with a pointer, i recommend some to return with a pointer for eg (return *sum);

rhydon-
Автор

please use dark mode for coding, it attracts the viewers.

_scars_
Автор

programing task

// Online C compiler to run C program online
#include <stdio.h>
#include <math.h>
int* multipliedNumber (int* num1, int* num2, int* multiplied){
*multiplied = *num1 * *num2;
return multiplied;
}

int main() {
// Write C code here
int num1 = 15;
int num2 = 25;
int multiplied;
multipliedNumber(&num1, &num2, &multiplied);
printf("result is: %d", multiplied);

return 0;
}

One_piece
Автор

answer is D



#include <stdio.h>

int* findMultiplication(int* num1, int* num2, int* multiplication){
*multiplication = (*num1) * (*num2);
return multiplication;
}

int main() {
// Write C code here
int number1 = 13;
int number2 = 9;
int multiplication;

int* result = findMultiplication(&number1, &number2, &multiplication);

printf("result is: %d", *result);

return 0;
}

geraldheng
Автор

Mam please answer this question.
Write a C program to print "True" if the given number's right most digit is even and second last right most digit is odd otherwise "False".
i.e. “True” for number like 12354, 798 etc

allproduct
Автор

Madam, how is this,
#include <stdio.h>
int multiblication(int* num1, int* num2)
{
int mult =*num1*(*num2);

return mult;
}
int main()
{
int x, y;

printf("ENTER NUM1: ");
scanf("%d", &x);

printf("ENTER NUM2: ");
scanf("%d", &y);

int result=multiblication(&x, &y);
printf("%d", result);

return 0;
}

abdirahmaanabdirashiid
Автор

Whats the use of this, we can do the same without pointers, right?

deshanjayasinghe
Автор

How come the function square is set as void ? Shouldn't it be int?

evildarkside
Автор

#include <stdio.h>

double* multNums (double* num1, double* num2, double* product) {

*product = *num1 * *num2;

return product;
}

int main(){

double number1 = 13, number2 = 9, product1;
double* product2;

product2 = multNums(&number1, &number2, &product1);

printf("The result = %lf", *product2);
return 0;
}

TheHeraldOfSpring
Автор

ans: (deff didnt look at instructions)
int* multi(int* num1, int* num2, int* sum);
int main(void)
{
int n1=5;//ints
int n2=10;
int sum;

int* result = multi(&n1, &n2, &sum);//start function with pointer params, put pointer result(sum) in pointer "result"

printf("%d\n", *result); // * to de refrence result, printf it

}

int* multi(int* num1, int* num2, int* sum)//declare param(int pointers) name
{
*sum = *num1 * *num2;// :o

return sum;//since program alr declared int*, no need to &sum
}

yourgray
Автор

i am confused table par tel gira hai ki sira🤔🤔🤔🤔

PrashantSingh-khwo