1 votes 1 votes Which line number contains an error or warning: Programming in C programming-in-c data-structures memory-management made-easy-test-series numerical-answers + – Souvik33 asked Jan 9, 2023 • reshown Jan 9, 2023 by Souvik33 Souvik33 726 views answer comment Share Follow See all 9 Comments See all 9 9 Comments reply DebRC commented Jan 9, 2023 reply Follow Share Assigning an integer pointer to a char pointer? I guess that would be a warning. 1 votes 1 votes Souvik33 commented Jan 9, 2023 reply Follow Share yep it’s correct, got it. I was considering the dangling pointer instead 🙄 0 votes 0 votes gatecse commented Jan 9, 2023 reply Follow Share @DebSujit That’s not the main error. char* can point to any memory location. 3 votes 3 votes DebRC commented Jan 10, 2023 i edited by DebRC Jan 10, 2023 reply Follow Share @gatecse Yes, sir it will still not be an error. It will be just a warning. But is this warning also compiler dependent? (Just curious)Also, no line seems to be error-prone here. 0 votes 0 votes Souvik33 commented Jan 10, 2023 reply Follow Share Running it in compilers, is generating no error/warning, but may be they are talking about theoretical errors. Compilers are getting very intelligent these days, and our education system prefers to follow 14yrs old theories. Best Example: https://gateoverflow.in/47/gate-cse-2012-question-15 0 votes 0 votes gatecse commented Jan 10, 2023 reply Follow Share @DebSujit The error is the “*” in ptr in line number 7. “*ptr” is a char and we are making a char pointing to a memory location which is not the intended use. Moreover on a 64 bit system, a 64 bit address will get truncated to an 8 bit one which most likely will cause runtime error. If we just use “ptr” instead of “*ptr” it should work fine. Also, current C does not require a typecase for malloc. @Souvik33 That question was a mistake. If it is asked now, GATE will be giving marks for all the correct answers and not just what was the standard 20 years back. That’s why they have “answer debate” option. Anything which is in standard books can get you mark and any answer related to changes which happened recently can also get you marks. But such changes affecting an answer is very very rare. 2 votes 2 votes DebRC commented Jan 10, 2023 reply Follow Share @gatecse Totally missed that they're dereferencing that char ptr before assigning. In general, does compilers throw error if we typecast address to a shorter variable (non-pointer)? Or it will throw error only when we try to do dereference. 3 votes 3 votes Souvik33 commented Jan 10, 2023 reply Follow Share @gatecse Thankyou for the clarification, I also missed that point. 1 votes 1 votes gatecse commented Jan 10, 2023 reply Follow Share @DebSujit Most compilers should be capable to find that error. But typecasting is not enforced by C language and so compilers need not error out. If you use ‘-Wall’ option for gcc, this should give a warning and ‘-Wall -Werror’ will make it an error. 3 votes 3 votes Please log in or register to add a comment.