Verification: Verified Account
Member for: 8 years (since Mar 28, 2018)
Type: Editor
Extra privileges: Asking questions
Voting posts down
Recategorizing any question
Editing any question
Editing any answer
Editing any comment
Closing any question
Flagging posts
Full name: Sambhrant Maurya
GATE Year: 2020
GATE Rank: 239
About:
Resume:
GitHub Profile Link:
DBLP Link:
Following standard books?: Yes
Home State:
Donate Me Link:
Messages from only those in my circle:
Test Series Access Lists

Activity by Sambhrant Maurya

Score: 220 points (ranked #36)
Title: Active
Exams Created: 0
Exams Taken: 0
No. of Edits: 0
Posts: 0
Questions: 0
Answers: 0
Comments: 0
Voted on: 12 questions, 0 answers
Gave out: 11 up votes, 1 down vote
Received: 0 up votes, 0 down votes
Reactions received: 0
Network Sites:

Wall for Sambhrant Maurya

Please log in or register to post on this wall.
syedmech47 Jun 4, 2020
Hi Sambhrant,

I saw your post, that being  a Mechanical Engineer you were able to crack the CS GATE with very good scores.

I am too a Mechanical Engineering Graduate, currently working full time and willing to aim for GATE 2022. So i have roughly 1.5 years of time and have to start the preparation from scratch. It would be great and helpful, if you can help me on how you started out preparing for the subjects, did you join any coaching institute and what are the list of resources and everything.

It will help me a lot to start preperation.

Thank You
Bikram Jul 16, 2019
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.
Bikram Jul 15, 2019
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 .
Bikram Jul 15, 2019
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.
Bikram Jul 15, 2019
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.