void

Is void a data type in C?

一曲冷凌霜 提交于 2019-12-17 08:29:41
问题 Is void a data type in the C programming language? If so, what type of values can it store? If we have int , float , char , etc., to store values, why is void needed? And what is the range of void? 回答1: Void is considered a data type (for organizational purposes), but it is basically a keyword to use as a placeholder where you would put a data type, to represent "no data". Hence, you can declare a routine which does not return a value as: void MyRoutine(); But, you cannot declare a variable

What does the return keyword do in a void method in Java?

有些话、适合烂在心里 提交于 2019-12-17 06:25:38
问题 I'm looking at a path finding tutorial and I noticed a return statement inside a void method (class PathTest , line 126): if ((x < 0) || (y < 0) || (x >= map.getWidthInTiles()) || (y >= map.getHeightInTiles())) { return; } I'm a novice at Java. Can anyone tell me why it's there? As far as I knew, return inside a void method isn't allowed. 回答1: It just exits the method at that point. Once return is executed, the rest of the code won't be executed. eg. public void test(int n) { if (n == 1) {

what does it mean to convert int to void* or vice versa?

岁酱吖の 提交于 2019-12-17 05:07:31
问题 What does it mean to convert an integer value to a void* or viceversa from a memory point of view? My understanding is void* is an address to a block of memory of unspecified length. This seems to be something like comparing apple with oranges. int myval = 5; void* ptr = (void*)myval; printf("%d",(int)ptr); I realized that I should have given the exact context where this is used. int main(int argc, char* argv[]) { long thread; /* Use long in case of a 64-bit system */ pthread_t* thread

What does casting to `void` really do?

和自甴很熟 提交于 2019-12-17 05:04:59
问题 An often used statement like (void)x; allows to suppress warnings about unused variable x . But if I try compiling the following, I get some results I don't quite understand: int main() { int x; (short)x; (void)x; (int)x; } Compiling this with g++, I get the following warnings: $ g++ test.cpp -Wall -Wextra -o test test.cpp: In function ‘int main()’: test.cpp:4:13: warning: statement has no effect [-Wunused-value] (short)x; ^ test.cpp:6:11: warning: statement has no effect [-Wunused-value]

What is the point of void operator in JavaScript?

倾然丶 夕夏残阳落幕 提交于 2019-12-17 03:02:48
问题 I've seen some people using void operator in their code. I have also seen this in href attributes: javascript:void(0) which doesn't seem any better than javascript:; So, what is the justification of using the void operator? 回答1: The JavaScript, the void operator is used to explicitly return undefined. Its a unary operator, meaning only one operand can be used with it. You can use it like shown below — standalone or with a parenthesis. void expression; void(expression); Lets see some examples

What's the better (cleaner) way to ignore output in PowerShell? [closed]

耗尽温柔 提交于 2019-12-17 02:24:24
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 9 months ago . Let's say you have a method or a cmdlet that returns something, but you don't want to use it and you don't want to output it. I found these two ways: Add-Item > $null [void]Add-Item Add-Item | Out-Null What do you use? Which is the better/cleaner approach? Why? 回答1: I just

Calling a non-void function without using its return value. What actually happens?

给你一囗甜甜゛ 提交于 2019-12-14 04:16:40
问题 So, I found a similar question here, but the answers are more about style and whether or not you are able to do it. My question is, what actually happens when you call a non-void function that returns an object, but you never assign or use said returned object? So, less about whether or not you can, because I absolutely know you can and understand the other question linked above... what does the compiler/runtime environment do? This is not a language specific question, but if you answer,

Undeclared Identifier after the void

若如初见. 提交于 2019-12-13 23:35:16
问题 I have got this error on the line where the void is it says undeclared identifier for sliderDidChange can some one please help me with this i can;t find any answers. h. file // // LightViewController.h // Flash Light // // Created by John Whitney on 12-07-27. // Copyright (c) 2012 Perfect Programs. All rights reserved. // #import <UIKit/UIKit.h> #import <AVFoundation/AVFoundation.h> @interface LightViewController : UIViewController { IBOutlet UISlider *slider; IBOutlet UISlider *theslider;

Objective c: method relation .h and .m

戏子无情 提交于 2019-12-13 22:46:04
问题 I have a theoretical question: but every method and IbAction must be declared in .h??? Because if I write a method (void) in .m and not in .h the project not has problem. 回答1: If you wanna access a function from another class you're gonna import that .h header file to make your compiler understand where to find those functions and how to translate them. 回答2: It is a guideline for how to implement your classes. Think of it in "C" terms. You define your prototypes in the .h (header) file and do

Towards understanding void pointers

限于喜欢 提交于 2019-12-13 12:03:10
问题 In my answer I mention that dereferencing a void pointer is a bad idea. However, what happens when I do this? #include <stdlib.h> int main (void) { void* c = malloc(4); *c; &c[0]; } Compilation: gcc prog.c -Wall -Wextra prog.c: In function 'main': prog.c:4:2: warning: dereferencing 'void *' pointer *c; ^~ prog.c:5:4: warning: dereferencing 'void *' pointer &c[0]; ^ prog.c:5:2: warning: statement with no effect [-Wunused-value] &c[0]; ^ Here is an image from Wandbox for those who say it didn't