Awesome q2a theme

User Sambhrant Maurya

Verification: Verified Account
Member for: 2 years (since Mar 28, 2018)
Type: Editor
Extra privileges: Voting posts down
Recategorizing any question
Editing any question
Editing any answer
Editing any comment
Closing any question
Selecting answer for any question
Viewing IPs of anonymous posts
Approving or rejecting posts
Hiding or showing any post
Viewing the newest users page
Full name: Sambhrant Maurya
GATE Year: 2019, 2020
GATE Rank: 4456, 239
About: "When something is important enough, you do it even if the odds are not in your favor." ~Elon Musk
Resume:
DBLP Link:
Following standard books?: Yes
Current City: Lucknow
Home State:
Donate Me Link:

Activity by Sambhrant Maurya

Score: 403 points (ranked #20)
Posts: 0
Questions: 116 (17 with best answer chosen)
Answers: 10 (4 chosen as best)
Comments: 233
Voted on: 14 questions, 36 answers
Gave out: 41 up votes, 9 down votes
Received: 61 up votes, 1 down vote

Wall for Sambhrant Maurya

https://gateoverflow.in/129778/test-by-bikram-2017-programming-test-2-18#c316933

A void function cannot return a value though it can have a return statement.
So, the answer is B .



yes you are correct, when we use void as return type it makes Return keyword as of no use ..

hence option B is correct, it provides error in return statement .

Reference:

http://stackoverflow.com/questions/17801793/function-cannot-return-a-value

even if u want to write a return statmnt for a void function(which is incorrect but lets suppose it compiles successfully )
 then also return should be written like return; and not return(m+2);

 
and also isnt it wrong that u have declred a function as void and then writing a return stmt to it.

#include <stdio.h>

void main(int n)
{
    printf("hello");
    return n;
}

gives output as  " hello "

so it return a value while return type is void .

even if u want to write a return statemnt for a void function(which is incorrect but lets suppose it compiles successfully ) then also return should be written like return; and not return(m+2);is it valid.
Jul 16, 2019 by Bikram
actually sizeof(int) is compiler dependent ..  so from this line

t = (p += sizeof(int))[-1];  
what we get is
if sizeof(int) = 2
[ in 16 bit systems it is 2 bytes, which is now obsolete we don't use 16 bit computer now a days]

then  
t = (p += sizeof(int))[-1]
t = (p = p + 2)[-1]
t = *(p + 2 -1) = *(p+1) = address of second element i.e. 'cd'

--------------
if sizeof(int) = 4 [ in 32 bit systems which is used now a days ]

then  

t = (p += sizeof(int))[-1]
t = (p = p + 4)[-1]
t = *(p + 4 -1) = *(p+3) = address of forth element i.e. 'gh' .
..................

#include <stdio.h>
void f(char**);  
int main()
{
char *argv[ ] = { "ab", "cd", "ef", "gh", "ij", "kl" };        // it creates character array.

     //   In char array address point to only starting of character array.


f(argv);               // function call with base address of char array.  
return 0;
}


void f(char **p)             // function call comes here. here p is pointer to pointer array

{
char *t;                             //create pointer variable
t = (p += sizeof(int))[-1];            //t = (p = p+4 ))[-1];

                                          // p point to "gh" starting of this char array.

                                       //       now P[-1] ; t= *(p-1); now t point to  "gh" array .

 
printf("%s\n", t);               // %s this tell to print string until % not encounter .

since every string stored end with %.
}

so it prints 'gh' .



    The size of an int is really compiler dependent. Back in the day, when processors were 16 bit, an int was 2 bytes. Nowadays, it's most often 4 bytes on a 32 bits system or 8 bytes on 64 bits system

    http://stackoverflow.com/questions/11438794/is-the-size-of-c-int-2-bytes-or-4-bytes

..................
 size of int we should take in 32 bit systems as 4 Bytes .

yes, 2 Bytes was used previously in 16 Bit systems but now we mostly use 32 Bit systems so size of int is 4 Bytes .
Jul 15, 2019 by Bikram
z=f(&i);

this correct ..

even if u want to write a return statmnt for a void function(which is incorrect but lets suppose it compiles successfully ) then also return should be written like return; and not return(m+2);

and also isnt it wrong that u have declred a function as void and then writing a return stmt to it.
Jul 15, 2019 by Bikram
you are correct, when we use void as return type it makes Return keyword as of no use ..

hence option B is correct, it provides error in return statement .

Reference:
https://stackoverflow.com/questions/17801793/function-cannot-return-a-value

A void function cannot return a value though it can have a return statement.
So, the answer is B.
Jul 15, 2019 by Bikram
7,393 questions
1,744 answers
10,711 comments
90,368 users