Viewed 2k times. Improve this question. Philippe Aubertin 1 1 gold badge 7 7 silver badges 21 21 bronze badges. Add a comment. Active Oldest Votes. Improve this answer.
Philippe Aubertin Philippe Aubertin 1 1 gold badge 7 7 silver badges 21 21 bronze badges. R Sahu R Sahu k 13 13 gold badges silver badges bronze badges. Ankur Ankur 3, 1 1 gold badge 20 20 silver badges 32 32 bronze badges. Sign up or log in Sign up using Google. This is because, arrays are not pointers. While they decay to pointers when passed to function, these pointers are not the actual arrays. Since address of array is static, it cannot be changed.
If we want to swap two arrays, then we have to swap the data. This code works fine for the above input because both the strings are of equal length. What if the strings to be swapped are of unequal lengths:. This code will crash because it will try to access str2 outside the range inside function swap. There is no fool proff way of swapping the above two strings, because str2 just does not have enough space to the content of str1. Functions can be called in two ways: Call by Value Call by reference In call by value , a copy of actual arguments is passed to formal arguments of the called function.
In the swap function, the values at the addresses of num1 and num2 are getting swapped. Thank you for your suggestion. We will look into it. Inside the function, exchange the content of these variables using a third variable. It takes two integer pointers as the arguments and swaps the values stored in the addresses pointed by these pointers. Web TypeScript React. Backend Node. Python tutorials. Java tutorials.
0コメント