A function that takes string parameter and returns integer pointer

NaveenKumar

I am wondering,How to write a function in c that return int pointer for any string input

The below function is my attempt to solve the requirment

int* methodname(char* param)
{
  int *a;
  int b=3;
  a=&b;
  return a; 
}

Please correct me for any mistakes.

venki

Returning local address is undefined, refer below code.

int* methodname(char* param)
{
  int *p = malloc(5*sizeof(int));
  . . .
  return p; 
}

Your declaration is ok but definition makes no sense, if any interviewer asked such kind of question their main intention is to check your programming skills, but your definition will not impress him, just write rough body(mainly concentrate on syntax, how you are returning and no undefined behavior) instead of implementing useless code.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Integer pointer as parameter of function

From Dev

function that takes iterables and returns a string

From Dev

A function that returns an array, but that also takes a function as parameter

From Dev

Write a function that takes as parameter a pointer to any of the functions

From Dev

How to forward declare a function that takes a pointer to a function as a parameter?

From Dev

Function, that takes string and number as parameter for creating filename

From Dev

Function rrot(rot, s) that takes as input an integer rot and a string s and returns a copy of s that s is reversed and then shifted by rot

From Dev

Write a function that takes 1 parameter: a string, s. It must return an integer denoting the length of the longest magical sub-sequence in s?

From Dev

a function that takes a list of integers as a parameter and returns a list of running totals

From Dev

Why is arrow function sent as a parameter when it simply returns the value it takes as is?

From Dev

Passing String Address As Parameter To Pointer To Pointer To Char Function

From Dev

Function that takes a string representing a decimal number and returns it in binary format

From Dev

Function that takes a string representing a decimal number and returns it in binary format

From Dev

Define a function called articleStats() that takes a string parameter named fileName

From Dev

How do I create an "increment" function that takes an integer pointer and increases its value?

From Dev

How do I create an "increment" function that takes an integer pointer and increases its value?

From Dev

Function Pointer as Function Parameter

From Dev

Function which takes an int pointer * as an argument and returns a struct. Storing data in struct struct* and printing results

From Dev

How to write a function that takes a positive integer N and returns a list of the first N natural numbers

From Dev

Pointer to pointer parameter in Swift function

From Dev

Pointer to Pointer to Void Function Parameter

From Dev

PInvoke function with pointer to pointer parameter

From Dev

Function returns unexpected pointer

From Dev

function that takes in and returns multiple values

From Dev

Write a function that takes as a parameter a list of strings and returns a list containing the lengths of each of the strings

From Dev

JS function takes an object as input and returns an object that performs actions on the object passed as a parameter

From Dev

void pointer in function parameter

From Dev

void pointer in function parameter

From Dev

memoizing a function that takes a set as parameter

Related Related

  1. 1

    Integer pointer as parameter of function

  2. 2

    function that takes iterables and returns a string

  3. 3

    A function that returns an array, but that also takes a function as parameter

  4. 4

    Write a function that takes as parameter a pointer to any of the functions

  5. 5

    How to forward declare a function that takes a pointer to a function as a parameter?

  6. 6

    Function, that takes string and number as parameter for creating filename

  7. 7

    Function rrot(rot, s) that takes as input an integer rot and a string s and returns a copy of s that s is reversed and then shifted by rot

  8. 8

    Write a function that takes 1 parameter: a string, s. It must return an integer denoting the length of the longest magical sub-sequence in s?

  9. 9

    a function that takes a list of integers as a parameter and returns a list of running totals

  10. 10

    Why is arrow function sent as a parameter when it simply returns the value it takes as is?

  11. 11

    Passing String Address As Parameter To Pointer To Pointer To Char Function

  12. 12

    Function that takes a string representing a decimal number and returns it in binary format

  13. 13

    Function that takes a string representing a decimal number and returns it in binary format

  14. 14

    Define a function called articleStats() that takes a string parameter named fileName

  15. 15

    How do I create an "increment" function that takes an integer pointer and increases its value?

  16. 16

    How do I create an "increment" function that takes an integer pointer and increases its value?

  17. 17

    Function Pointer as Function Parameter

  18. 18

    Function which takes an int pointer * as an argument and returns a struct. Storing data in struct struct* and printing results

  19. 19

    How to write a function that takes a positive integer N and returns a list of the first N natural numbers

  20. 20

    Pointer to pointer parameter in Swift function

  21. 21

    Pointer to Pointer to Void Function Parameter

  22. 22

    PInvoke function with pointer to pointer parameter

  23. 23

    Function returns unexpected pointer

  24. 24

    function that takes in and returns multiple values

  25. 25

    Write a function that takes as a parameter a list of strings and returns a list containing the lengths of each of the strings

  26. 26

    JS function takes an object as input and returns an object that performs actions on the object passed as a parameter

  27. 27

    void pointer in function parameter

  28. 28

    void pointer in function parameter

  29. 29

    memoizing a function that takes a set as parameter

HotTag

Archive