mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-13 18:24:39 +02:00
Merge pull request #1399 from himanshu81494/master
example function added for call by reference
This commit is contained in:
@@ -8,7 +8,7 @@ commented code and explained as they go.
|
|||||||
|
|
||||||
... to write more inline code tutorials. Just grab an existing file from
|
... to write more inline code tutorials. Just grab an existing file from
|
||||||
this repo and copy the formatting (don't worry, it's all very simple).
|
this repo and copy the formatting (don't worry, it's all very simple).
|
||||||
Make a new file, send a pull request, and if it passes muster I'll get it up pronto.
|
Make a new file, send a pull request, and if it passes master I'll get it up pronto.
|
||||||
Remember to fill in the "contributors" fields so you get credited
|
Remember to fill in the "contributors" fields so you get credited
|
||||||
properly!
|
properly!
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@ contributors:
|
|||||||
- ["Árpád Goretity", "http://twitter.com/H2CO3_iOS"]
|
- ["Árpád Goretity", "http://twitter.com/H2CO3_iOS"]
|
||||||
- ["Jakub Trzebiatowski", "http://cbs.stgn.pl"]
|
- ["Jakub Trzebiatowski", "http://cbs.stgn.pl"]
|
||||||
- ["Marco Scannadinari", "https://marcoms.github.io"]
|
- ["Marco Scannadinari", "https://marcoms.github.io"]
|
||||||
|
- ["himanshu", "https://github.com/himanshu81494"]
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -316,7 +317,29 @@ int main (int argc, char** argv)
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
using "goto" in C
|
||||||
|
*/
|
||||||
|
typedef enum { false, true } bool;
|
||||||
|
// for C don't have bool as data type :(
|
||||||
|
bool disaster = false;
|
||||||
|
int i, j;
|
||||||
|
for(i=0;i<100;++i)
|
||||||
|
for(j=0;j<100;++j)
|
||||||
|
{
|
||||||
|
if((i + j) >= 150)
|
||||||
|
disaster = true;
|
||||||
|
if(disaster)
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
error :
|
||||||
|
printf("Error occured at i = %d & j = %d.\n", i, j);
|
||||||
|
/*
|
||||||
|
https://ideone.com/GuPhd6
|
||||||
|
this will print out "Error occured at i = 52 & j = 99."
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
// Typecasting
|
// Typecasting
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
@@ -482,7 +505,24 @@ char c[] = "This is a test.";
|
|||||||
str_reverse(c);
|
str_reverse(c);
|
||||||
printf("%s\n", c); // => ".tset a si sihT"
|
printf("%s\n", c); // => ".tset a si sihT"
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
|
as we can return only one variable
|
||||||
|
to change values of more than one variables we use call by reference
|
||||||
|
*/
|
||||||
|
void swapTwoNumbers(int *a, int *b)
|
||||||
|
{
|
||||||
|
int temp = *a;
|
||||||
|
*a = *b;
|
||||||
|
*b = temp;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
int first = 10;
|
||||||
|
int second = 20;
|
||||||
|
printf("first: %d\nsecond: %d\n", first, second);
|
||||||
|
swapTwoNumbers(&first, &second);
|
||||||
|
printf("first: %d\nsecond: %d\n", first, second);
|
||||||
|
// values will be swapped
|
||||||
|
*/
|
||||||
// if referring to external variables outside function, must use extern keyword.
|
// if referring to external variables outside function, must use extern keyword.
|
||||||
int i = 0;
|
int i = 0;
|
||||||
void testFunc() {
|
void testFunc() {
|
||||||
|
@@ -4,6 +4,7 @@ filename: learnjson.json
|
|||||||
contributors:
|
contributors:
|
||||||
- ["Anna Harren", "https://github.com/iirelu"]
|
- ["Anna Harren", "https://github.com/iirelu"]
|
||||||
- ["Marco Scannadinari", "https://github.com/marcoms"]
|
- ["Marco Scannadinari", "https://github.com/marcoms"]
|
||||||
|
- ["himanshu", "https://github.com/himanshu81494"]
|
||||||
---
|
---
|
||||||
|
|
||||||
As JSON is an extremely simple data-interchange format, this is most likely going
|
As JSON is an extremely simple data-interchange format, this is most likely going
|
||||||
@@ -16,6 +17,11 @@ but they should be avoided for better compatibility.
|
|||||||
|
|
||||||
For the purposes of this, however, everything is going to be 100% valid JSON. Luckily, it kind of speaks for itself.
|
For the purposes of this, however, everything is going to be 100% valid JSON. Luckily, it kind of speaks for itself.
|
||||||
|
|
||||||
|
Data types supported by JSON includes: numbers, string, boolean, array, object and null.
|
||||||
|
Supporting browsers are: Firefox(Mozilla) 3.5, Internet Explorer 8, Chrome, Opera 10, Safari 4.
|
||||||
|
JSON file type for JSON files is ".json". The MIME type for JSON text is "application/json"
|
||||||
|
Drawbacks of JSON include lack of type definition and some sort of DTD.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"key": "value",
|
"key": "value",
|
||||||
|
Reference in New Issue
Block a user